luogu#P7828. [CCO 2021] Swap Swap Sort
[CCO 2021] Swap Swap Sort
Problem Description
You have a sequence of length , where each element is a positive integer not greater than .
Your friend invented a sorting algorithm that can sort the sequence according to a permutation of . After sorting, for any two unequal numbers in the sequence, their relative order is the same as their relative order in the permutation. His algorithm only uses adjacent swaps, and it always guarantees the minimum number of operations. For convenience, he calls this permutation of the target permutation.
For example, if the sequence is and the target permutation is , then after sorting it becomes .
You are very interested in how many swaps your friend’s sorting algorithm performs under different target permutations. To study the pattern, you initially set the target permutation to , and then perform operations on it. In each operation, you swap the positions of two adjacent numbers in the target permutation. After each swap, you want to know how many swaps would be performed if you use his sorting algorithm to sort the original sequence.
Input Format
The first line contains three integers .
The second line contains positive integers , representing the original sequence.
The next lines each contain one positive integer , meaning you swap the -th and the -th numbers in the target permutation.
Output Format
For each query, output one integer, representing the required value.
5 4 3
1 4 2 1 2
3
2
1
4
2
2
Hint
Constraints
Because the official data package is too large, this problem only includes of the official testdata.
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , , .
Source
CCO2021 D1T1
Translated by ChatGPT 5