#SRD0000031. Nghịch thế khi xóa phần tử (Dynamic Inversion)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghịch thế khi xóa phần tử (Dynamic Inversion)
Dynamic Inversion
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of . There are deletion instructions. Each instruction names the value to remove from the current sequence, not its position. No value is removed more than once. Before removing , print the current number of inversions with and ; then delete that value.
Input
The first line contains , followed by the permutation values and then values to be deleted. The PHOJ version uses one data set in this format.
Output
Print exactly inversion counts, each measured immediately before the corresponding deletion.
Subtasks
- Subtask 1 (10 points): ; ; ; is a permutation of ; ; deleted values are distinct and lie in .
- Subtask 2 (20 points): ; ; ; is a permutation of ; ; deleted values are distinct and lie in .
- Subtask 3 (30 points): ; ; ; is a permutation of ; ; deleted values are distinct and lie in .
- Subtask 4 (40 points): ; ; ; is a permutation of ; ; deleted values are distinct and lie in .
Examples
Input
5 4
1
5
3
4
2
5
1
4
2
Output
5
2
2
1
Explanation
The initial permutation has five inversions; print before deleting value . The remaining has two; print before deleting . The final two counts are and .