#P15557. [CCPC 2025 哈尔滨站] 1-2-按位或子序列问题
[CCPC 2025 哈尔滨站] 1-2-按位或子序列问题
Problem Description
You are given a sequence of length that contains only and (). You may perform the following operation any number of times:
- Choose , delete and from the sequence, and insert at their original position, where denotes bitwise OR.
- Note that after each operation, the value of decreases by .
For example, if and you choose to operate, then after the operation the sequence becomes .
After performing some operations, how many essentially different sequences can be produced? Output the result modulo . Two sequences are different if and only if their lengths are different, or there exists some position where the numbers differ.
Since may be very large, the sequence is given in a run-length compressed format, where equal numbers are compressed into segments. In particular, it is guaranteed that the lengths of the segments of equal numbers are monotonically non-decreasing from left to right.
Input Format
The first line contains an integer (), the number of test cases.
Then each test case is given as follows:
The first line contains two integers (), representing the number of segments, and the value of .
The second line contains integers (), where is the length of the -th segment in the sequence.
Since adjacent segments have different values, the length- sequence, where , can be uniquely determined by and .
It is guaranteed that over all test cases.
Output Format
For each test case, output one integer, the answer modulo .
2
3 1
1 1 2
8 2
1 2 3 4 5 6 7 8
7
2961300
Hint
In Sample 1, the sequence represented by the first test case is . After performing some operations, the essentially different sequences that can be obtained are:
- .
- .
- .
- .
- .
- .
- .
Translated by ChatGPT 5