#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 mm and a sequence bb of nn numbers are given. Initially, there is a piece on the first position of bb, and b1b_1 is decreased by 11. After that, the two players take turns. On each move, suppose the current piece is at position ii. The player may move the piece to a position jj such that j[i,min(i+m,n)]j \in [i, \min(i + m, n)] and bj>0b_j > 0, then decrease bjb_j by 11. 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 bb used in “ge mo” is a non-empty contiguous subsequence of a sequence aa. Of course, both the sequence aa and the sequence bb used in each round are chosen by YSGS.

Now they play qq 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 n,m,q,typen, m, q, type. The meanings of n,m,qn, m, q are the same as in the statement. typetype indicates the type of the current testdata. type=1type = 1 means this testdata is compressed, and type=0type = 0 means it is not. The testdata guarantees that when q>106q > {10}^6, type=1type = 1.

The second line contains nn positive integers. The ii-th positive integer represents aia_i, with the same meaning as in the statement.

If type=1type = 1, the third line contains four positive integers A,B,C,PA, B, C, P, 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 l>rl > r, then you also need to swap l,rl, r.

The testdata guarantees 0AB<P0 \le A B < P, 0C<P0 \le C < P, P(B+1)<2311P (B + 1) < 2^{31} - 1.

If type=0type = 0, the next qq lines each contain two positive integers l,rl, r, with the same meaning as in the statement.

Output Format

Let ansi{ans}_i indicate whether YSGH will win in the ii-th query. If YSGH will win, then ansi=1{ans}_i = 1, otherwise ansi=0{ans}_i = 0.

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 25%25\% of the testdata, n,m,q10n, m, q \le 10, ai2a_i \le 2.
For 55%55\% of the testdata, n,m,q5×103n, m, q \le 5 \times {10}^3.
For another 15%15\% of the testdata, n105n \le {10}^5, m5m \le 5.
For 90%90\% of the testdata, n,m,q106n, m, q \le {10}^6.
For 100%100\% of the testdata, 1n,m1061 \le n, m \le {10}^6, 1q1071 \le q \le {10}^7, 1ai1091 \le a_i \le {10}^9.

Translated by ChatGPT 5