#P8449. [LSOT-1] 逆序对

[LSOT-1] 逆序对

Background

Inversion pairs are really fun.

Problem Description

You need to maintain a sequence and support the following 44 operations:

  1. Swap two intervals.
  2. Move an interval backward to between the kk-th number and the (k+1)(k+1)-th number.
  3. Insert a number xx at the end.
  4. Insert a number xx at the beginning.

After each operation, the indices of the numbers are re-numbered in the new sequence from the first number to the kk-th number as 11 to kk.

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 n,mn,m, representing the length of the initial sequence and the number of operations.

The next line contains nn positive integers a1,a2,,ana_1,a_2,\dots,a_n, representing the initial sequence.

The next mm lines each start with an integer tt indicating the operation type, followed by:

  • If t=1t=1, input four positive integers l1,r1,l2,r2l_1,r_1,l_2,r_2, meaning to swap the whole interval [l1,r1][l_1,r_1] with the whole interval [l2,r2][l_2,r_2]. It is guaranteed that l1r1<l2r2l_1\le r_1< l_2\le r_2.
  • If t=2t=2, input three positive integers l,r,kl,r,k, meaning to move the interval [l,r][l,r] to between the kk-th number and the (k+1)(k+1)-th number of the sequence. It is guaranteed that r<kr<k.
  • If t=3t=3, input one positive integer xx, meaning to insert xx at the end of the sequence.
  • If t=4t=4, input one positive integer xx, meaning to insert xx 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 [1,1][1,1] and interval [2,2][2,2]. The sequence becomes 3 4 5 7 2 6.

In the second operation, move interval [1,1][1,1] to between the 33-rd and the 44-th numbers. The sequence becomes 4 5 3 7 2 6.

In the third operation, insert 1111 at the end of the sequence. The sequence becomes 4 5 3 7 2 6 11.

In the fourth operation, insert 11 at the beginning of the sequence. The sequence becomes 1 4 5 3 7 2 6 11.

[Constraints]

"This problem uses bundled testdata."

  • Subtask 1(10 pts): n,m102\texttt{Subtask 1(10 pts): }n,m\le 10^2.
  • Subtask 2(15 pts): n,m103\texttt{Subtask 2(15 pts): }n,m\le 10^3.
  • Subtask 3(20 pts): \texttt{Subtask 3(20 pts): }Operations 1 and 2 do not appear.
  • Subtask 4(20 pts): \texttt{Subtask 4(20 pts): }Operations 3 and 4 do not appear.
  • Subtask 5(35 pts): \texttt{Subtask 5(35 pts): }No special restrictions.

For 100%100\% of the testdata, 1n,m2×1051\le n,m \le 2\times 10^5, ai2×106a_i\le 2\times10^6, and it is guaranteed that all numbers in aa are distinct at any time.

Translated by ChatGPT 5