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 sequence of length . The point’s initial position is . Repeat the following operations:
- If the entire sequence consists of only one character, stop.
- Let the point’s current position be . Uniformly at random choose a position , move the point to , flip the character at , and add to the total cost, where , and are two given constants.
- Go back to step 1.
You need to perform modifications. Specifically, each modification includes:
- Flip the at position in the sequence.
- Query the expected cost after the process stops, when the initial position is .
Note that once a modification is made, it remains effective.
You need to output the XOR sum of the answers to the queries, where each answer is the expected cost modulo .
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 string is generated with .
R.init(seed1);
for (int i = 1; i <= n; i++) seq[i] = R.Rand() & 1;
For the queries, 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 . Their meanings are described in “Description”.
Output Format
One line with one integer , representing the XOR sum of the query results, where each expected cost is taken modulo .
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: , , answer is ; , , answer is ; , , answer is . Modulo , they are , , and , and the XOR sum is .
[Constraints]
This problem uses subtask evaluation.
For of the testdata, , , , .
| Subtask | Special Property | Subtask Score | Dependencies | Time Limit | ||
|---|---|---|---|---|---|---|
| 0 | A | 5 | 1s | |||
| 1 | / | 18 | Subtask 0 | |||
| 2 | 12 | Subtask 0~1 | ||||
| 3 | A | 10 | Subtask 0 | |||
| 4 | / | Subtask 0~3 | ||||
| 5 | 45 | Subtask 0~4 | 2s | |||
Special Property A: .
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