Xor sum

3.7

19 votes
Advanced Data Structures, Bit Manipulation, Data Structures, Easy, Segment Trees
Problem

You are given an array A[] of size N. Now you are given Q queries to be performed over this array. In each query, you are given 2 space separated integers L and R. For each query, you need to you need to find the summation of the xor-sum of all triplets (i,j,k) of the sub-array L...R , where Li<j<kR.

In short, you need to find (A[i]A[j]A[k]), over all triplets (i,j,k) , such that Li<j<kR . Print the answer for each query , Modulo 109+7

Input Format

The first line contains a single integer N.

The next line contains  array A[] of N integers.

The next line contains 2 space separated integers Q and 2.

Each of the next Q lines contains two space separated integers L and R

Output Format :

Print Q lines, the ith line denoting the answer to the ith query, Modulo 109+7

Input Constraints :

1N,Q105

1A[i]1012

1LRN

Sample Input
4
1 2 3 4
1 2
1 4
Sample Output
18
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

(123)+(234)+(124)+(134)=18

Editor Image

?