#P7346. Reincarnation XOR Operations
Reincarnation XOR Operations
Reincarnation XOR Operations
You are given a sequence a of length n (indexed from 1 to n) and m operations to perform on it. The operations are of four types:
- Type 1: Given two integers x and y, update every element whose index i satisfies \[ i \equiv 0 \pmod{x} \] by performing an XOR with y (i.e. a[i] = a[i] \oplus y). Note: since indices start from 1, these are exactly the multiples of x.
- Type 2: Given an integer x, query the current value of a[x] and output it.
- Type 3: Given four integers x, y, u, and v, compare a[x] with y. If \[ a[x] \le y, \] then reincarnate by re-executing all operations in the range [u,v] that are of Type 1 (i.e. the XOR operations).
- Type 4: Given an integer x, re-execute the operation with index x (the operations are 1-indexed).
Operations are processed in the given order. When an operation is re-executed due to a reincarnation (Types 3 and 4), its effect is applied again on the current sequence. It is guaranteed that the reincarnation points do not intersect.
Input Format:
inputFormat
The first line contains two integers n and m.
The second line contains n integers, representing the initial sequence a[1], a[2], \dots, a[n].
Then follow m lines, each representing an operation:
- Type 1:
1 x y
- Type 2:
2 x
- Type 3:
3 x y u v
- Type 4:
4 x
outputFormat
For each query operation (Type 2), print the requested number on a new line.
sample
5 5
1 2 3 4 5
1 2 1
2 3
3 1 3 1 1
4 1
2 4
3
5
</p>