luogu#P7953. [✗✓OI R1] 逆转比特

[✗✓OI R1] 逆转比特

Background

myy is traveling in Foshan, Guangdong, so he made a “Gaoming” problem.

Problem Description

A point performs a random walk on a 0/10/1 sequence of length nn. The point’s initial position is pp. Repeat the following operations:

  1. If the entire sequence consists of only one character, stop.
  2. Let the point’s current position be pp. Uniformly at random choose a position qq, move the point to qq, flip the character at qq, and add f(pq)f(|p-q|) to the total cost, where f(x)=Ax2+Bxf(x)=Ax^2+Bx, and A,BA,B are two given constants.
  3. Go back to step 1.

You need to perform qq modifications. Specifically, each modification includes:

  1. Flip the 0/10/1 at position idx\mathit{idx} in the sequence.
  2. Query the expected cost after the process stops, when the initial position is pp.

Note that once a modification is made, it remains effective.

You need to output the XOR sum of the answers to the qq queries, where each answer is the expected cost modulo 998244353998244353.

Since the input and output size is large, the data is generated randomly as follows:

struct Random {
  unsigned long long X;
  void init(unsigned long long seed) { X = seed; }
  unsigned long long Rand() {
    X ^= X << 13;
    X ^= X >> 7;
    X ^= X << 17;
    return X;
  }
} R;

The initial 0101 string is generated with seed1\mathit{seed1}.

R.init(seed1);
for (int i = 1; i <= n; i++) seq[i] = R.Rand() & 1;

For the qq queries, seed2\mathit{seed2} is given.

R.init(seed2);
for (int i = 1; i <= q; i++) {
  idx = R.Rand() % n + 1, p = R.Rand() % n + 1;
  ans ^= query(idx, p);
}

Input Format

One line with six integers n,q,seed1,seed2,A,Bn,q,\mathit{seed1},\mathit{seed2},A,B. Their meanings are described in “Description”.

Output Format

One line with one integer ans\mathit{ans}, representing the XOR sum of the qq query results, where each expected cost is taken modulo 998244353998244353.

3 3 114514 1919810 0 1
831870297
5 3 998244353 1000000007 1 1
694472000
21 17 233 234 5 17
367211664

Hint

[Sample Explanation]

Explanation for sample 1:
The three queries are: 110110, p=3p=3, answer is 114\dfrac{11}{4}; 010010, p=3p=3, answer is 176\dfrac{17}{6}; 110110, p=1p=1, answer is 114\dfrac{11}{4}. Modulo 998244353998244353, they are 249561091249561091, 831870297831870297, and 249561091249561091, and the XOR sum is 831870297831870297.

[Constraints]

This problem uses subtask evaluation.

For 100%100\% of the testdata, 3n3×1063 \leq n \leq 3\times10^6, 1q3×1061 \leq q \leq 3\times10^6, 0A,B<9982443530 \leq A, B < 998244353, seed1,seed2[0,264)\mathit{seed1}, \mathit{seed2}\in [0, 2^{64}).

Subtask nn\le qq\le Special Property Subtask Score Dependencies Time Limit
0 55 55 A 5 1s
1 5050 / 18 Subtask 0
2 600600 5050 12 Subtask 0~1
3 30003000 A 10 Subtask 0
4 / Subtask 0~3
5 3×1063\times10^6 45 Subtask 0~4 2s

Special Property A: A=0A = 0.

By convention, there should be an interesting postscript here, but since you have already finished the “Ake Monthly Contest”, you probably do not have the patience to read it, so there is none.

Translated by ChatGPT 5