#P3157. [CQOI2011] 动态逆序对
[CQOI2011] 动态逆序对
Description
For a sequence , its number of inversions is defined as the size of the set
You are given a permutation of . According to some order, elements are deleted one by one. Your task is to count the number of inversions of the entire sequence before each deletion.
Input Format
The first line contains two integers and , which are the initial number of elements and the number of deletions.
The next lines each contain a positive integer between , which is the initial permutation.
Then the next lines each contain a positive integer, in order, which is the element to delete at each step.
Output Format
Output lines, where the -th line is the number of inversions before deleting the -th element.
5 4
1
5
3
4
2
5
1
4
2
5
2
2
1
Hint
Constraints
For of the testdata, , .
Sample Explanation
The sequences before each deletion are:
Translated by ChatGPT 5
京公网安备 11011102002149号