#P11326. 【MX-S7-T4】「SMOI-R2」XA-Game
【MX-S7-T4】「SMOI-R2」XA-Game
Background
Original problem link: https://oier.team/problems/S7D.
Problem Description
Alice and Bob are playing a game.
Initially, there is a 01 sequence of length , with positions numbered . The two players take turns operating, and Alice moves first.
Alice's move is to choose any two adjacent numbers in the sequence and merge them into their xor value (i.e. the ^ operator in C++).
Bob's move is to choose any two adjacent numbers in the sequence and merge them into their and value (i.e. the & operator in C++).
The game continues until there is only one number left in the sequence. If the final remaining number is , Alice wins; otherwise, Bob wins.
Before the game starts, Bob casts spells to adjust the initial sequence. The -th spell changes the number at position to .
Alice wants to know: if both players use optimal strategies, how many possible initial sequences (before Bob casts his spells) can allow her to win the game. Since the answer may be very large, you need to output it modulo the prime .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases. Then for each test case:
- The first line contains two non-negative integers , representing the length of the 01 sequence and the number of Bob's spell operations.
- The next lines: the -th line contains two non-negative integers , meaning that the -th spell changes the number at position to . It is guaranteed that are given in strictly increasing order, i.e. .
Output Format
For each test case:
- Output a single line with one integer, the answer modulo .
5
3 0
5 2
2 0
4 1
6 3
1 0
2 1
4 1
1234 4
52 1
110 1
520 0
999 1
114514 0
3
12
32
27109943
596672839
Hint
[Sample Explanation #1]
In the first test case, the sequences that allow Alice to win are , , and , for a total of .
In the second test case, the sequences that allow Alice to win are , , , , , , , , , , , and , for a total of .
For the sequence , after Bob finishes casting spells it becomes . Alice's first move can merge the fourth and fifth numbers, making the sequence become . It can be seen that no matter how Bob plays, Alice will win.
[Sample #2]
See game/game2.in and game/game2.ans in the attachments.
This sample satisfies the constraints of test points .
[Sample #3]
See game/game3.in and game/game3.ans in the attachments.
This sample satisfies the constraints of test points .
[Sample #4]
See game/game4.in and game/game4.ans in the attachments.
This sample satisfies the constraints of test points .
[Sample #5]
See game/game5.in and game/game5.ans in the attachments.
This sample satisfies the constraints of test points .
[Constraints]
For all testdata, it is guaranteed that: , , , , , , .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| A | ||||
| B | ||||
| C | ||||
| None | ||||
- Special property A: .
- Special property B: , and .
- Special property C: , and there are no two adjacent in , i.e. .
Translated by ChatGPT 5