#P5612. Sequence Maintenance Operations

    ID: 18842 Type: Default 1000ms 256MiB

Sequence Maintenance Operations

Sequence Maintenance Operations

We maintain a sequence of n non-negative integers \(a_1,a_2,\ldots,a_n\). You are to process q operations on this sequence. The operations can be of three types:

  1. Update XOR: Given an interval \([l,r]\) and an integer \(x\), update each element in the interval as follows: \(a_i = a_i \oplus x\) for \(l \le i \le r\), where \(\oplus\) denotes bitwise XOR.
  2. Sort Subarray: Given an interval \([l,r]\), sort the subarray \(a_l, a_{l+1}, \ldots, a_r\) in non-decreasing order.
  3. XOR Query: Given an interval \([l,r]\), compute and output the XOR sum of the numbers in that interval, i.e., \(\bigoplus_{i=l}^{r} a_i\).

Operations are processed sequentially. For every operation of type 3, you should output the result on a separate line.

inputFormat

The input begins with an integer \(n\) \( (1 \le n \le N)\) representing the number of elements in the sequence.

The second line contains \(n\) space-separated non-negative integers \(a_1, a_2, \ldots, a_n\).

The third line contains an integer \(q\) \( (1 \le q \le Q)\), the number of operations.

Each of the following \(q\) lines describes an operation in one of the following formats:

  • Type 1 (Update XOR): 1 l r x
  • Type 2 (Sort Subarray): 2 l r
  • Type 3 (XOR Query): 3 l r

outputFormat

For each operation of type 3, output the resulting XOR sum in a separate line.

sample

5
1 2 3 4 5
5
3 1 5
1 2 4 1
3 1 5
2 1 3
3 1 3
1

0 0

</p>