#P1975. [国家集训队] 排队
[国家集训队] 排队
Description
Sit in a row and eat fruit; the fruit is sweet and tasty, everyone smiles happily. One for you, one for me; the big one goes to you, the small one stays with me. After we finish eating, we sing a song, and everyone is cheerful.
The children of Red Star Kindergarten line up in a long queue to eat fruit. However, because their heights differ, the queue looks uneven and not very neat. Let the height of the -th child be .
Each time, the teacher selects two children and swaps their positions. Please help compute the number of inversions in the sequence after each swap. For the teacher’s convenience, you should also output the inversion count of the sequence before any swaps are performed.
Description
Input Format
- The first line contains a positive integer , the number of children.
- The second line contains space-separated positive integers , representing the heights in the initial queue.
- The third line contains a positive integer , the number of swap operations.
- The following lines each contain two positive integers , indicating that the children at positions and are swapped.
Output Format
Output lines.
- Line 1: the number of inversions in the sequence before any swap.
- For , line : the number of inversions in the sequence after performing swap .
3
130 150 140
2
2 3
1 3
1
0
3
Hint
[Sample explanation]
Before any operation, is an inversion.
After operation 1, the sequence is , and there are no inversions.
After operation 2, the sequence is , and , , are inversions, totaling .
[Constraints]
For of the testdata, .
For of the testdata, .
Additionally, for of the testdata, all are distinct.
Additionally, for of the testdata, .
These two types of testdata are disjoint.
For of the testdata, , , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号