Range XOR
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
2.0s
Python 3
2.0s
Memory limit:
977M
Problem type
You are given an array of integers and must answer
range queries.
Each query gives indices and
and asks for the bitwise XOR of all values in the subarray
.
Input
The first line contains the integer .
The second line contains integers, the values in the array.
The third line contains the integer , the number of queries.
Each of the next lines contains two integers
and
, asking for the XOR of all values in
the range
.
Output
For each query, output a line containing the XOR of the requested range.
Constraints
Example 1
Input
10
1 5 10 5 3 2 5 10 5 9
4
1 4
7 8
1 3
5 9
Output
11
15
14
11
Example 2
Input
10
2 6 7 7 6 10 4 6 8 9
4
5 10
1 6
6 8
1 9
Output
15
8
8
2
Hints
Hint 1
With respect to XOR, every value is its own inverse: .
Hint 2
Think about how prefix sums answer range-sum queries, then replace addition with XOR.
Comments