#P5652. 基础博弈练习题
基础博弈练习题
Description
YSGH and YGSH are playing “ge mo” (pinyin: gémó), and YSGS is watching.
The rules are as follows. First, a positive integer and a sequence of numbers are given. Initially, there is a piece on the first position of , and is decreased by . After that, the two players take turns. On each move, suppose the current piece is at position . The player may move the piece to a position such that and , then decrease by . YSGH moves first. Whoever cannot make a move loses.
It is well known that both YSGH and YGSH are extremely smart, so both will use optimal strategies.
The sequence used in “ge mo” is a non-empty contiguous subsequence of a sequence . Of course, both the sequence and the sequence used in each round are chosen by YSGS.
Now they play rounds of the game. Given the interval used in each round, please determine who will win each round.
Input Format
Because the data size of this problem is large, direct input and output will take much more time than computation. Therefore, when there are too many queries, the input and output of the queries are compressed.
The first line contains four positive integers . The meanings of are the same as in the statement. indicates the type of the current testdata. means this testdata is compressed, and means it is not. The testdata guarantees that when , .
The second line contains positive integers. The -th positive integer represents , with the same meaning as in the statement.
If , the third line contains four positive integers , describing how queries are generated.
int A, B, C, P;
inline int rnd() { return A = (A * B + C) % P; }
For each query, call:
l = rnd() % n + 1, r = rnd() % n + 1;
If the generated , then you also need to swap .
The testdata guarantees , , .
If , the next lines each contain two positive integers , with the same meaning as in the statement.
Output Format
Let indicate whether YSGH will win in the -th query. If YSGH will win, then , otherwise .
Output one line with one integer, which is $\displaystyle \left( \sum_{i = 1}^{q} i^2 \cdot {ans}_i \right)\! \bmod 2^{32}$.
5 2 3 0
2 4 1 2 3
1 5
3 5
3 4
5
Hint
For of the testdata, , .
For of the testdata, .
For another of the testdata, , .
For of the testdata, .
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号