#P93. [CSP-S 2024] Arena championship
[CSP-S 2024] Arena championship
Person in Charge
Problem Description
Little S wants to organize a tournament game. If there are participants, the game will proceed in rounds:
- In the first round, participants with IDs and compete, participants with IDs and compete, and so on, up to participants with IDs and .
- In the second round, only the winners from the first round remain, and adjacent pairs compete sequentially.
- This continues similarly until the -th round, where only the winners from the -th round remain, and the first two and last two compete separately (i.e., the semifinals).
- The -th round is the final between the two winners of the semifinals.
After determining the advancement rules, Little S sets the match rules as a "challenge" system. Specifically, each participant has an ability value , where each is an integer in . For each match, a number or is drawn randomly. Let denote the number drawn for the -th match in the -th round. If , the participant with the smaller ID is the "challenger"; if , the participant with the larger ID is the challenger. The challenger wins if and only if their ability value . In other words, the outcome of the match depends solely on the challenger's ability value and the current round number, and is independent of the other participant's ability value.
Now, Little S receives registration information from participants one by one, each reporting their ability value. Little S assigns IDs to the participants in the order they register. Little S is interested in determining the minimum number of additional participants needed to make the total number of participants a power of , and the sum of IDs of all possible champions after a complete tournament under all possible outcomes.
Formally, let be the smallest non-negative integer such that . Then, additional participants must be added, and their ability values can be any integers in . If an additional participant has a chance to win, their ID must also be included in the answer.
Little S finds this problem too simple, so he gives you queries . For each , Little S asks you to compute the answer when only the first participants have registered.
Input Format
This problem contains multiple test cases. However, different test cases are generated by modifying only , while other content remains unchanged. Refer to the following format. Here, denotes the bitwise XOR operator, and denotes the remainder when is divided by .
The first line of input contains two positive integers , representing the number of registered participants and the number of queries.
The second line contains non-negative integers , which are used to compute the actual ability values.
The third line contains positive integers , representing the queries.
Let be the smallest non-negative integer such that . The next lines each contain numbers (without spaces), where the -th number in the -th line represents the drawn value for the -th match in the -th round.
Note that since queries only require rounding the number of participants up to , where , you may not use all the input values.
The next line contains a positive integer , indicating the number of test cases.
The following lines each describe a test case with non-negative integers . The actual ability values for the test case are computed as , where .
Output Format
Output lines. For each test case, let be the answer for the -th query (). You need to output a single integer per line, representing $(1 \times A_1) \oplus (2 \times A_2) \oplus \dots \oplus (m \times A_m)$.
Samples
5 5
0 0 0 0 0
5 4 1 2 3
1001
10
1
4
2 1 0 0
1 2 1 0
0 2 3 1
2 2 0 1
5
19
7
1
Sample 1 Explanation
There are test cases. Here, only the first test case is explained. The actual ability values for the participants are . The queries are for prefixes of lengths .
- For the prefix of length , since there is only participant , the answer is .
- For the prefix of length , since is already a power of , no additional participants are needed. The draw means participant is the challenger. Since , participant wins, and the answer is .
- For the prefix of length , participant wins against (since , is the challenger, and ). Although the ability value of participant is unknown, participant will always win against (since , is the challenger, and ). In the final, either or can win (since , is the challenger; if , wins; otherwise, wins). Thus, the answer is .
- For the prefix of length , since , participant wins the final.
- For the prefix of length , it can be shown that possible winners include participants , , and , so the answer is .
Thus, the output for this test case is $(1 \times 19) \oplus (2 \times 4) \oplus (3 \times 1) \oplus (4 \times 1) \oplus (5 \times 5) = 5$.
Sample 2
See the files arena/arena2.in and arena/arena2.ans in the contestant directory.
This sample satisfies Special Property A.
Sample 3
See the files arena/arena3.in and arena/arena3.ans in the contestant directory.
This sample satisfies Special Property B.
Sample 4
See the files arena/arena4.in and arena/arena4.ans in the contestant directory.
Sample 5
See the files arena/arena5.in and arena/arena5.ans in the contestant directory.
Data Range
For all test cases, it is guaranteed that: , , , .
| Test Case | Special Property A | Special Property B | ||
|---|---|---|---|---|
| No | No | |||
| Yes | ||||
| No | Yes | |||
| No | ||||
| Yes | ||||
| No | Yes | |||
| No | ||||
Special Property A: All queries are powers of .
Special Property B: All .