#P3157. [CQOI2011] 动态逆序对

    ID: 2206 远端评测题 1500ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011重庆各省省选树状数组分治主席树

[CQOI2011] 动态逆序对

Description

For a sequence aa, its number of inversions is defined as the size of the set

{(i,j)i<jai>aj}.\{(i,j)\mid i<j \wedge a_i > a_j \}.

You are given a permutation of 1n1\sim n. According to some order, mm 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 nn and mm, which are the initial number of elements and the number of deletions.
The next nn lines each contain a positive integer between 1n1 \sim n, which is the initial permutation.
Then the next mm lines each contain a positive integer, in order, which is the element to delete at each step.

Output Format

Output mm lines, where the ii-th line is the number of inversions before deleting the ii-th element.

5 4
1
5
3
4
2
5
1
4
2
5
2
2
1

Hint

Constraints
For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1m500001 \le m \le 50000.

Sample Explanation
The sequences before each deletion are:

1,5,3,4,21,5,3,4,2 1,3,4,21,3,4,2 3,4,23,4,2 3,23,2

Translated by ChatGPT 5