#P6186. [NOI Online #1 提高组] 冒泡排序
[NOI Online #1 提高组] 冒泡排序
Problem Description
You are given a permutation of . Then there are operations, of two types:
- Swap operation: given , swap the -th number and the -th number in the current permutation.
- Query operation: given , find the number of inversions in the current permutation after performing rounds of bubble sort.
The pseudocode for performing one round of bubble sort on a permutation of length is:
for i = 1 to n-1:
if p[i] > p[i + 1]:
swap(p[i], p[i + 1])
Input Format
The first line contains two integers and , representing the length of the permutation and the number of operations.
The second line contains integers representing the permutation .
The next lines each contain two integers and , describing an operation:
- If , then this operation is a swap operation, and .
- If , then this operation is a query operation, and .
Output Format
For each query operation, output one line with one integer representing the answer.
3 6
1 2 3
2 0
1 1
1 2
2 0
2 1
2 2
0
2
1
0
Hint
Explanation for Sample 1
First operation: the permutation is . After rounds of bubble sort it is , with inversions.
Second operation: the permutation becomes .
Third operation: the permutation becomes .
Fourth operation: after rounds of bubble sort the permutation is , with inversions.
Fifth operation: after round of bubble sort the permutation becomes , with inversion.
Sixth operation: after rounds of bubble sort the permutation becomes , with inversions.
Constraints and Notes
For testdata 1 2: .
For testdata 3 4: .
For testdata 5 6: the number of swap operations does not exceed .
For all testdata: , , , .
Translated by ChatGPT 5