#P8995. [北大集训 2021] 随机数据
[北大集训 2021] 随机数据
Background
CTT2021 D4T3
Problem Description
There are items, numbered . The value of item is defined as .
A and B take turns playing a game, which consists of multiple rounds.
At the start of each round, if all available items have been taken, the game ends immediately. Otherwise, A must choose an untaken item and take it.
Suppose the item A takes has index . Next, B may choose one untaken item from item and item to take, or B may choose to skip this action. Then the game proceeds to the next round. In particular, if both of these items have already been taken, B can only choose to skip.
Both A and B want to maximize the sum of values of the items they take. We assume both A and B play optimally.
In addition, before the game starts, some items may be unavailable. During the game, unavailable items are ignored, i.e., neither A nor B can take unavailable items. When all available items have been taken, the game ends immediately.
Initially, all items are available. Your program needs to support operations. In each operation, given an : if item is unavailable, it becomes available; if it is available, it becomes unavailable. After each operation, you need to answer: assuming the game starts from the current state, what is the sum of values of the items taken by B when the game ends.
Unfortunately, this is an IO problem: the number of items may be up to . As an OIer, you cannot handle data at such a large scale, so will be generated in a special way: given an array of length , .
Input Format
The first line contains four positive integers , with $1 < n \le 10^{16}, 1 \le d < n, 1 \le m \le 2 \times 10^4, q \le 10^5$.
The second line contains integers. The -th integer represents the value of , with .
The next lines each contain an integer , representing an operation on item . It is guaranteed that .
Output Format
Output lines, each containing one integer, corresponding to the answer after each operation.
5 2 3 2
1 3 2
1
1
3
4
10 4 5 5
40 355 190 215 161
3
4
0
3
4
581
460
420
541
702
Hint
Subtask 1 (5 pts): .
Subtask 2 (10 pts): .
Subtask 3 (15 pts): .
Subtask 4 (30 pts): .
Subtask 5 (40 pts): No special constraints.
If needed, you can use __int128 to handle long long multiplication modulo. Below is an example of using __int128 to compute :
long long a = 1e15;
long long b = 1e15;
long long m = 12345678910;
long long c = ((__int128) a * b) % m;
Translated by ChatGPT 5