#P4425. [HNOI/AHOI2018] 转盘

    ID: 3361 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018线段树各省省选安徽湖南枚举,暴力

[HNOI/AHOI2018] 转盘

Description

Xiao G and Xiao H plan to have a dinner, but to keep things simple, the statement is as follows:

There is a turntable with nn items arranged in a circle (numbered 1n1 \sim n). The ii-th item appears at time TiT_i.

At time 00, Xiao G can choose any one of the nn items; denote it by s0s_0. If at time ii he chooses item sis_i, then at time i+1i+1 he can either keep the current item or move to the next item. When sis_i equals nn, the next item is item 11; otherwise it is item si+1s_i + 1. At every time (including time 00), if the item Xiao G chooses has already appeared, then he will mark it. Xiao H wants to know, under the optimal strategy of choosing items, when can Xiao G mark all items.

However, the appearance times of items will be modified from time to time. We describe this as mm modifications, each changing the appearance time of one item. After each modification, you must also output the answer for the current state. For some test points, Xiao H also imposes a forced online constraint.

Input Format

The first line contains three non-negative integers nn, mm, and pp, meaning there are nn items and mm modifications. The value of pp is either 00 or 11; when p=1p = 1, the problem is forced online; otherwise p=0p = 0.

The next line contains nn non-negative integers. The ii-th number TiT_i is the appearance time of item ii.

Each of the next mm lines contains two non-negative integers xx and yy, representing one modification and its query. The modification works as follows:

  1. If p=0p = 0, set the appearance time of item xx to yy, i.e., TxyT_x \leftarrow y.
  2. If p=1p = 1, first XOR xx and yy with LastAns respectively to obtain xx' and yy', then set TxyT_{x'} \leftarrow y'. Here LastAns is the result of the previous query; in particular, for the first modification, LastAns is the answer for the initial state.

It is guaranteed that the input is valid.

Output Format

Output one integer on the first line, the answer for the initial state.

Then output mm lines, each containing one integer, the answer after each modification.

5 3 0
1 2 3 4 5
3 5
5 0
1 4
5
7
6
7

Hint

【Constraints】

::cute-table[]{tuack} | Test point id | nn | mm | Ti/TxT_i / T_x | pp | | :-: | :-: | :-: | :-: | :-: | | 1 | 10\le 10 | 10\le 10 | 10\le 10 | =0=0 | | 2 | 1000\le 1000 | =0=0 | 1000\le 1000 | ^ | | 3 | 100000\le 100000 | ^ | 100000\le 100000 | ^ | | 4 | 5000\le 5000 | 5000\le 5000 | ^ | ^ | | 5 | 80000\le 80000 | 80000\le 80000 | ^ | ^ | | 6 | ^ | ^ | ^ | =1=1 | | 7 | 90000\le 90000 | 90000\le 90000 | ^ | =0=0 | | 8 | ^ | ^ | ^ | =1=1 | | 9 | 100000\le 100000 | 100000\le 100000 | ^ | =0=0 | | 10 | ^ | ^ | ^ | =1=1|

For all testdata, it is guaranteed that 3n1053 \le n \le 10^5, 0m1050 \le m \le 10^5, and 0Ti/Tx1050 \le T_i / T_x \le 10^5.

Translated by ChatGPT 5