#P4991. Bitwise Sequence Operations

    ID: 18230 Type: Default 1000ms 256MiB

Bitwise Sequence Operations

Bitwise Sequence Operations

You are given a sequence of integers. You need to process two types of modification operations and answer query operations.

There are two modification operations, and one query operation:

  • Operation 1: 1 l r k – For every index i in the range \(l \le i \le r\), flip (bitwise invert) the last \(k\) bits of the number. That is, if the last \(k\) bits of a number \(a_i\) are represented in binary, change every 0 to 1 and every 1 to 0 in those bits. Formally, let \(mask = 2^k - 1\). Then update \(a_i = (a_i \& \sim mask) | (mask - (a_i \& mask))\).
  • Operation 2: 2 l r k – For every index i in the range \(l \le i \le r\), reverse the order of the last \(k\) bits of the number. For example, if a number is represented in 8-bit binary as 10100111 and \(k=5\), then its last 5 bits 00111 reversed become 11100, so the new number becomes the binary 10111100.
  • Operation 3: 3 w – Query the value at position \(w\) of the sequence.

To simplify the problem, we impose the following restrictions:

  • The parameter \(k\) for modification operations is restricted to a fixed set of values.
  • There are \(t\) distinct values of \(k\).
  • For each distinct \(k\), all modification operations using that \(k\) are given in one group.

Input Format

The input begins with three integers \(n\), \(t\), and \(q\) where \(n\) is the length of the sequence, \(t\) is the number of groups of modification operations (each with a fixed \(k\)), and \(q\) is the number of query operations.

The second line contains \(n\) space‐separated integers, representing the initial sequence. Each of the next \(t\) groups has the following format:

  k m
  op l r
  op l r
  ... (m operations, where op is either 1 or 2)

After the \(t\) groups, there are \(q\) lines, each containing a single integer \(w\), representing a query operation "3 w". Process all modification operations in the order they are given, then answer each query by printing the value at position \(w\) (1-indexed) in the final sequence.

Output Format

For each query, output the resulting value on its own line.

inputFormat

The first line contains three integers \(n\), \(t\), and \(q\) (\(1 \le n \le 10^5\), \(t, q \ge 1\)).

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) representing the initial sequence.

Then, for each of the \(t\) groups, the first line of the group contains two integers: \(k\) (the fixed bit-length for that group, \(1 \le k \le 32\)) and \(m\) (the number of modification operations in this group). Each of the following \(m\) lines contains three integers: op l r where op is either 1 or 2 indicating the operation type, and \(l\) and \(r\) (1-indexed) specify the range of indices to be modified.

Finally, there are \(q\) lines, each containing a single integer \(w\) (1-indexed), representing a query operation.

outputFormat

For each query operation, print the value present at the queried position \(w\) in the final sequence. Each answer should be printed on a separate line.

sample

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

1 5

</p>