Increasing Xor Sequence
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given a sequence of n integers a1, ..., an. Count the number of sequences b = b1, ..., bn such that: 0 ≤ b1 ≤ ... ≤ bn < 231 and (a1 XOR b1) ≤ … ≤ (an XOR bn). Return this count, modulo 109+7.
Here XOR denotes the bitwise XOR.
The first line of input will contain an integer T, the number of test cases.
Each test case will be in two lines.
The first line of the case will contain an integer n.
The next line of the case will contain n space separated integers a1,...,an.
Output a single number, the number of sequences, modulo 109+7.
- 1 ≤ T ≤ 100
- 1 ≤ n ≤ 5
- 0 ≤ ai < 231
Input: 4 1 42 5 5 4 3 2 1 4 1194533513 122420337 1448417648 120078455 3 31 2047 2147483647 Output: 147483634 986095186 0 468598063
In the first case, there are 231 possible sequences, so the answer is 231 modulo 109+7 = 147483634
For the second case, one possible example of a valid sequence is b = 9, 9, 18, 19, 32. We can check that this sequence is nondecreasing, and also, we have (a1 XOR b1) = 12, (a2 XOR b2) = 13, (a3 XOR b3) = 17, (a4 XOR b4) = 17, (a5 XOR b5) = 33, which is also nondecreasing.
For the third case, no sequences satisfy the conditions.
|Tags||bitmasks, cook80, digit-dp, lg5293, medium-hard|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.