#codefestivalchinaj. [code_festival_china_j]XORAND
[code_festival_china_j]XORAND
Problem
Yu loves bitwise AND operation and big number. Yu's friend Yihuo loves bitwise XOR operation and small number. They are good friends that whenever someone sends them an array of numbers as a gift, they share the numbers with each other.
For an array of non-negative integers , let be the result of bitwise AND between all numbers in the array (), and let be the result of bitwise XOR between all numbers in the array (). Yu's satisfaction value for is , Yihuo's satisfaction value for the same array of numbers is (Note that Yihuo loves small number. The less is, the more Yihuo satisfies.)
Whenever they receive an array of non-negative integer as a gift, they cut the array in the middle and Yu gets the former part, Yihuo gets the latter part. The place they cut the array is determined to maximize the sum of each satisfaction value for the array each get. To say more precisely, they cut the array at after the -th number within , which maximizes the sum of Yu's satisfaction value for and Yihuo's satisfaction value for .
You will be given a elements non-negative integer array and numbers of query. The -th query asks "How much is the sum of their satisfaction value when we give to Yu and Yihuo". Your task is to answer all queries in the given order.
Note that each query is described by integers (), but those integers are not given directly. You must calculate those integers from the last query's answer as described in the Input section. This means that you must calculate the answer of queries in the given order.
Input
... :
- On the first line, you will be given two integers (), () separated by space, the number of elements in the array and the number of queries respectively.
- On the second line, you will be given integers separated by space. The -th () integer is ().
- Following lines are the information of the query. The -th () line contains integers (), () separated by space.
Calculate , , the exact integers in the query as following.
- ,
- For all that satisfies , let be the answer to the -th query.
Note that each answer may be a negative number that the absolute value of is used to obtain and . It is guaranteed that holds.
Output
Output lines. The -th () line should contain the answer to the -th query. Make sure to insert a line break at the end of the output.
Input Example 1
7 4
7 3 5 4 6 3 1
2 5
2 5
3 4
5 1
Output Example 1
-1
2
2
5
The answer to each query is as following.
- For the first query, , . The array of numbers will be separated to and , which provides Yu's satisfaction value AND , Yihuo's satisfaction value XOR , summed up to .
- For the second query, MOD , MOD . The array will be separated to and , which provides Yu's satisfaction value AND and Yihuo's satisfaction value XOR , summed up to .
- For the third query, MOD , MOD . The array can only be separated to and , which provides Yu's satisfaction value and Yihuo's satisfaction value , summed up to .
- For the fourth query, MOD , MOD . The array will be separated to and , which provides Yu's satisfaction value and Yihuo's satisfaction value XOR XOR , summed up to .
Input Example 2
20 30
1 4 3 6 9 9 6 7 5 3 5 4 9 4 1 2 14 5 11 1
14 18
4 15
2 10
3 13
20 15
7 12
18 10
9 15
20 12
5 7
6 10
8 12
4 14
17 11
15 16
17 7
20 13
8 9
14 17
13 16
5 6
4 11
5 7
4 6
12 16
16 15
13 16
2 7
8 15
10 16
Output Example 2
-4
-1
0
-2
-1
-4
-1
4
3
-1
3
-2
6
3
10
5
1
-2
-1
-5
1
-6
-4
-1
-4
0
-9
4
3
2
The , for each query is as following.
14 18
9 20
4 12
4 14
3 18
9 14
3 15
11 17
5 17
9 11
8 12
12 16
7 17
4 18
19 20
8 18
6 19
10 11
17 20
15 18
11 12
6 13
12 14
9 11
14 18
1 20
14 17
12 17
13 20
14 20