#P10891. 【烂题杯 Round 1】消灭劳嗝
【烂题杯 Round 1】消灭劳嗝
Problem Description
You need to eliminate Lao Ge.
Given a permutation of length , define . You may understand it as the set of indices of prefix maximums in the suffix starting at . For example, for , and .
There are queries. Each query gives , and you need to compute:
$$\left(\left(\sum_{l\le x\le y\le r} |S_x\cup S_y|-\sum_{\substack{{1\le x<l}\\{r<y\le n}}} |S_x\cup S_y|\right)\bmod P+P\right)\bmod P$$where .
Input Format
Since the input file is too large to upload, we will read the data in a weird way.
The first line contains two non-negative integers and , representing the permutation length and the random seed.
Initially let . Next, an integer is given in one line, representing the number of operations on the permutation.
Next, we will perform operations on the permutation . For the -th operation (1-indexed), let and . You need to swap and . Here denotes bitwise XOR.
For C++, the code is as follows:
l = (1ll * X * (X ^ i)) % n + 1;
r = (X ^ (1ll * i * i)) % n + 1;
Next, an integer is given in one line, representing the number of queries.
For the -th query (1-indexed), let $l=\min((X\times i+(X\oplus (X\times i)))\bmod n,(X-i+(X\oplus (X+i)))\bmod n)+1$ and $r=\max((X\times i+(X\oplus (X\times i)))\bmod n,(X-i+(X\oplus (X+i)))\bmod n)+1$. These are the query parameters.
For C++, the code is as follows:
l = min((1ll * X * i + (X ^ (1ll * X * i))) % n, (X - i + (X ^ (X + i))) % n) + 1;
r = max((1ll * X * i + (X ^ (1ll * X * i))) % n, (X - i + (X ^ (X + i))) % n) + 1;
Output Format
Since the output file is too large to upload, we will output the data in a weird way.
Output one line with one integer, representing the XOR of all answers over the queries.
5 3
4
5
998244304
10 114514
191981
3
998244191
Hint
Sample 1 Explanation:
After the operations, .
After decrypting the queries, the real queries are as follows:
4 5
2 3
1 5
3 4
3 5
After decrypting the output, the real output is as follows:
5
998244350
33
1
11
For the first query, and . Then .
For the second last query, do not forget the terms with .
Constraints:
For of the testdata, and .
For of the testdata, and .
For of the testdata, and .
For of the testdata, and .
For of the testdata, , , , , and all are distinct.
All contestants should pay attention to the impact of constant factors.
Translated by ChatGPT 5