You are given an array aa of nn integers a1,a2,a3,…,an.
You have to answer qq independent queries, each consisting of two integers ll and rr.
You can find more details about XOR operation here.
Input
The first line contains two integers nn and qq (1≤n,q≤2⋅105)(1≤n,q≤2⋅105) — the length of the array aa and the number of queries.
The next line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai<230)(0≤ai<230) — the elements of the array aa.
The ii-th of the next qq lines contains two integers lili and riri (1≤li≤ri≤n)(1≤li≤ri≤n) — the description of the ii-th query.
Output
For each query, output a single integer — the answer to that query.
Example
input
7 6 3 0 3 3 1 2 3 3 4 4 6 3 7 5 6 1 6 2 2
output
-1 1 1 -1 2 0
Note
In the first query, l=3,r=4l=3,r=4, subarray = [3,3][3,3]. We can apply operation only to the subarrays of length 11, which won't change the array; hence it is impossible to make all elements equal to 00.
In the second query, l=4,r=6l=4,r=6, subarray = [3,1,2][3,1,2]. We can choose the whole subarray (L=4,R=6) and replace all elements by their XOR (3⊕1⊕2)=0(3⊕1⊕2)=0, making the subarray [0,0,0].
In the fifth query, l=1,r=6l=1,r=6, subarray = [3,0,3,3,1,2][3,0,3,3,1,2]. We can make the operations as follows:
对于一个区间,无论选哪对l, r做多少次异或操作,因为不能自己异或自己,所以异或和总是不变的。所以要想使一个区间都变为0,这个区间必须在初始时异或和就为0
异或和不变分析:
选择L, R, 设异或之后将L - R都替换为num,这是个奇数区间,奇数个num异或后还是num。
若是查询某个奇数区间:此区间全为0则 0 次操作
此区间异或和为0则 1 次操作
否则无法变为0
若是查询某个偶数区间:首先此区间要异或和全为0才可能产生答案
设此区间为l - r,因为只能选奇数区间异或,所以在l - r内必须存在一个奇数的异或和为0的子区间,先操作一次使这个子区间都为0,再选一个0和剩下的偶数个数异或,至此整个区间都为0
#include
#include