Prefix XOR Sum

4.8

12 votes
Introduction to Dynamic Programming 1, Bitmask, Dynamic Programming, Algorithms
Problem

You are given an array A containing N integers and Q queries. Each query is denoted by two integers L,R. The answer to a query is AL+(ALAL+1)++(ALAL+1AR), where  denotes the bitwise XOR operator. 

Input format

  • The first line contains two integers N denoting the size of array A and  Q  denoting the number of queries:
  • The second line contains N space-separated integers A1,A2,,AN - denoting the elements of A.
  • Each of the next Q  lines contains two integers L,R.

Output format

For each test query, print the answer in a separate line.

Constraints

1N,Q21050Ai<2301LRN

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

The answer to the first query is =A3+(A3A4)=2+(26)=2+4=6.

The answer to the second query is =A1+(A1A2)+(A1A2A3)=1+(17)+(172)=1+6+4=11.

Editor Image

?