XOR of numbers

3

9 votes
Bit Manipulation, Basic Programming, Bitmask, Prefix, Basics of Bit Manipulation
Problem

You are given an array a of n numbers and q queries. In each query, l, r find XOR of all n numbers except the range [l,r].

Input format

  • The first line contains two integers n denoting the number of elements and q denoting the number of test cases.
  • The second line of each test case contains n space-separated integers.
  • The next q lines contain two integers l and r.

Output format

For each test case, print the answer as described in the problem statement.

Example 

Let the array a be [1,2,3,4] and you are given a query (2,3), then print the XOR of all the array a without the range [2,3].

Hence, the answer will be 1{XOR}4

Constraints

1n105

1q105

1ai109

1l,rn

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, the XOR of the array without the numbers in the range [2,3]. So, compute XOR of 1,4,5 it equals to 0.

 

Editor Image

?