Innocence
Time limit1sMemory limit512 MB
Count arrays of length N with every element in [L, R] whose XOR equals K, modulo 1e9+7, for several K values per test case.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
David is a young child. He likes playing combinatorial games, for example, the Nim game. He is just an amateur but he is sophisticated with game theory. This time he has prepared a problem for you.
Given integers , , and , count the number of arrays of length whose elements all lie between and (inclusive) and whose bitwise exclusive-OR equals . Print the count modulo .
David also wants you to answer several values of to make sure your solution is completely correct.
Input
The first line contains one integer , the number of test cases.
Each test case is described as follows. The first line contains four space-separated integers , , and , meaning there are queries with the same , , but different . The second line contains space-separated integers .
, , , , .
No more than 100 test cases fail to satisfy and .
Output
For each query, print the answer modulo on its own line.
Hint
In the first sample, there are two ways to select one number 3 and one number 4 such that the exclusive-OR of them is 7.
In the second sample, there are three ways to select one number 3 and two numbers 4 and one way to select three numbers 3 such that the exclusive-OR of them is 3.