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:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions