#P8449. [LSOT-1] 逆序对
[LSOT-1] 逆序对
Background
Inversion pairs are really fun.
Problem Description
You need to maintain a sequence and support the following operations:
- Swap two intervals.
- Move an interval backward to between the -th number and the -th number.
- Insert a number at the end.
- Insert a number at the beginning.
After each operation, the indices of the numbers are re-numbered in the new sequence from the first number to the -th number as to .
Now, after every operation, please output the parity of the number of inversion pairs in the entire sequence.
Input Format
The first line contains two positive integers , representing the length of the initial sequence and the number of operations.
The next line contains positive integers , representing the initial sequence.
The next lines each start with an integer indicating the operation type, followed by:
- If , input four positive integers , meaning to swap the whole interval with the whole interval . It is guaranteed that .
- If , input three positive integers , meaning to move the interval to between the -th number and the -th number of the sequence. It is guaranteed that .
- If , input one positive integer , meaning to insert at the end of the sequence.
- If , input one positive integer , meaning to insert at the beginning of the sequence.
Output Format
After each operation, if the number of inversion pairs is even, output even; otherwise output odd.
6 4
4 3 5 7 2 6
1 1 1 2 2
2 1 1 3
3 11
4 1
odd
odd
odd
odd
Hint
[Sample Explanation]
In the first operation, swap interval and interval . The sequence becomes 3 4 5 7 2 6.
In the second operation, move interval to between the -rd and the -th numbers. The sequence becomes 4 5 3 7 2 6.
In the third operation, insert at the end of the sequence. The sequence becomes 4 5 3 7 2 6 11.
In the fourth operation, insert at the beginning of the sequence. The sequence becomes 1 4 5 3 7 2 6 11.
[Constraints]
"This problem uses bundled testdata."
- .
- .
- Operations 1 and 2 do not appear.
- Operations 3 and 4 do not appear.
- No special restrictions.
For of the testdata, , , and it is guaranteed that all numbers in are distinct at any time.
Translated by ChatGPT 5