#P8449. Sequence Inversion Parity Maintenance

    ID: 21625 Type: Default 1000ms 256MiB

Sequence Inversion Parity Maintenance

Sequence Inversion Parity Maintenance

You are given an initially empty sequence. You need to maintain the sequence while supporting the following four operations:

  1. Interval Swap: Given two contiguous intervals in the sequence specified by indices \([l_1, r_1]\) and \([l_2, r_2]\) (with \(r_1 < l_2\)), swap these intervals.
  2. Interval Move (to later position): Given an interval \([l, r]\) and an index \(k\), remove the subarray from \(l\) to \(r\) and insert it so that it lies between the \(k\)th and \(k+1\)th elements of the remaining sequence. (Note that after removal the sequence is re-indexed.)
  3. Append Operation: Insert a number \(x\) at the end of the sequence.
  4. Prepend Operation: Insert a number \(x\) at the beginning of the sequence.

After each operation, re-index the sequence from 1 to the current length and output the parity of the inversion count of the entire sequence. An inversion is defined as a pair of indices \((i, j)\) such that \(i a_j\). The output should be even if the number of inversions is even and odd if it is odd.

Note: All indices used in operations are 1-indexed.

inputFormat

The first line contains an integer \(Q\) (the number of operations). Each of the following \(Q\) lines describes one operation. The operations are given in one of the following formats:

  • For Interval Swap: 1 l1 r1 l2 r2
  • For Interval Move: 2 l r k (move the subarray from index \(l\) to \(r\) to after the \(k\)th element of the re-indexed sequence after removal)
  • For Append: 3 x
  • For Prepend: 4 x

outputFormat

After each operation, output a single line containing either even or odd, which corresponds to the parity of the inversion count of the current sequence.

sample

6
3 3
3 1
4 2
1 1 1 2 2
2 2 3 1
4 4
even

odd even odd odd even

</p>