You are given an array of integers, let's name it *drumroll* . You need to answer queries of types.
The first type of query asks you to insert a number after some index in the array. It is guaranteed that this newly inserted value is greater than or equal to any value in the array at that moment. Note that this query changes the array.
In the second type query, you are given integers and . Using these integers, you would calculate and by the code described below. Let's create another sorted array of all numbers that lie between the indices and (inclusive) of the array . For the second type query, you need to find the bitwise xor of all numbers that lie between indices and (inclusive) of the array .
To find and from and , you follow this process given below.
You maintain the answer to the last query of type 2 in variable ans
. Note that ans
is initially . Now, whenever you get a query of type ,
L = 1 + ((ans ^ l) % SIZE);
R = 1 + ((ans ^ r) % SIZE);
if(L > R) swap(L, R);
P = 1 + ((p ^ ans) % (R - L + 1));
Q = 1 + ((q ^ ans) % (R - L + 1));
if(P > Q) swap(P, Q);
Here ^
denotes the bitwise xor operator, and %
denotes the modulo operator and is the current size of the array.
Input:
First line of input contains integers and , denoting the number of elements in the array and the number of queries you need to answer. Next line contains space separated integers denoting the elements of the array .
Each of the next lines describe a query. Each query contains several space separated integers.
If it is a type query, the query contains space separated integers. The first integer is , denoting that it is a type query and next integers are and , meaning that you need to insert after the index in the array.
If it is a type query, the query contains space separated integers. The first integer is , denoting that it is a type query and next integers are and , with their meaning explained in the problem statement.
Output:
For each query of type , print the answer in a new line.
Constraints:
current size of array
any value in the array at that moment