AND queries

1

2 votes
Mathematics, Walsh-Hadarm transform, Fast Fourier transform, Medium-Hard, Linear Algebra
Problem

You are given an integer array A of length N and M queries. For each query, you are given three integers L,R,X and you should find the number of triplets (i,j,k) such that (Li,j,kR) and (Ai&Aj&Ak=X).

Symbol & denotes bitwise operator AND.

Input format:

First line contains one integer N (1N100000).

Next line contains N space-separated integers denoting the array A (0Ai255).

The next line contains one integer M (1M50000).

Next M lines contains three space-separated integers L,R,X (1LRN,0X255)

Output format:

For each query, print the required answer modulo 109+7 in a new line.

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

For 8-th query, there are 6 triplets: (2,2,3)(2,3,2)(2,3,3)(3,2,2)(3,2,3)(3,3,2).

Editor Image

?