All problems

Problem 485

XOR of Subarray Queries

Medium · 20 pts · Array, Bit Manipulation, Prefix Sum

Problem

Answer Q queries on a fixed array: each query L R asks for A[L] XOR A[L+1] XOR ... XOR A[R] (zero-based, inclusive). Since x XOR x = 0, prefix XORs work exactly like prefix sums: with P[i] = A[0] XOR ... XOR A[i-1], the answer is P[R+1] XOR P[L]. This answers every query in O(1) after O(N) preprocessing.

Input

First line: N. Second line: N integers. Third line: Q. Next Q lines: L and R.

Output

Print the answer to each query on its own line.

Constraints

1 <= N, Q <= 100000; 0 <= A[i] <= 1000000000; 0 <= L <= R < N

Example input

4
1 3 4 8
4
0 1
1 2
0 3
3 3

Example output

2
7
14
8

Explanation

For the array 1 3 4 8, the query 0 1 gives 1 XOR 3 = 2, the query 1 2 gives 3 XOR 4 = 7, the query 0 3 gives 14 and the query 3 3 gives 8.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Find the Repeating and Missing Numbers Next: Set Matrix Zeroes