You are given a 1indexed array A, of length n, and q queries to be performed on it. The queries are of two types
You maintain the answer to the last query of type 2 in variable ans
. Note that ans
is initially 0. Now, whenever you get a query of type 2, calculate l, r,i and j as :
l = 1 + ((ans ^ L) % n);
r = 1 + ((ans ^ R) % n);
if(l > r) swap(l, r);
i = 1 + ((I ^ ans) % (r - l + 1));
j = 1 + ((J ^ ans) % (r - l + 1));
if(i > j) swap(i, j);
Here ^
denotes the bitwise xor operator, and %
denotes the modulo operator
Note that array A is NOT changed in a query of second type.
Input
Output
For each of the query of type 2, print the required value on a new line.
Constraints
1≤n,q,L,R,I,J≤5×104
1≤Ai,x≤105
At any instant, all elements of A are distinct
In the first query, l,r,i,j come out to be 1,2,1,2 respectively. Therefore, array B=[8,10]. and the required answer is B1⊕B2=8⊕10=2
Then, in second query, we update A4 to 1. Now, A=[10,8,5,1]
In query 3, value of ans
is 2 . Using this value, l,r,i,j come out to be 3,4,1,1 respectively. Array B=[1,5], and the required answer is B1=1