#abc330e. E - Mex and Update

E - Mex and Update

Score : 475475 points

问题描述

你已获得一个长度为 NN 的序列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N)

按照给定顺序,依次回答以下 QQ 个查询请求。

kk 个查询采用如下格式给出:

$i_k$ $x_k$
  • 首先,将 AikA_{i_k} 改变为 xkx_k。这一改变将会对后续的查询产生影响。
  • 然后,输出 AAmex\rm{mex} 值。
    • AAmex\rm{mex} 值是指在 AA 中不存在的最小非负整数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) of length NN.
Respond to the following QQ queries in the order they are given.

The kk-th query is given in the following format:

$i_k$ $x_k$
  • First, change AikA_{i_k} to xkx_k. This change will carry over to subsequent queries.
  • Then, print the mex\rm{mex} of AA.
    • The mex\rm{mex} of AA is the smallest non-negative integer not contained in AA.

Constraints

  • All input values are integers.
  • 1N,Q2×1051 \le N,Q \le 2 \times 10^5
  • 0Ai1090 \le A_i \le 10^9
  • 1ikN1 \le i_k \le N
  • 0xk1090 \le x_k \le 10^9

Input

Input is given from Standard Input in the following format:

NN QQ

A1A_1 A2A_2 \dots ANA_N

i1i_1 x1x_1

i2i_2 x2x_2

\vdots

iQi_Q xQx_Q

Output

Print QQ lines in total.
The kk-th line should contain the answer to the kk-th query as an integer.

Sample Input 1

8 5
2 0 2 2 1 1 2 5
4 3
4 4
6 3
8 1000000000
2 1

Sample Output 1

4
3
6
5
0

Initially, the sequence AA is (2,0,2,2,1,1,2,5)(2,0,2,2,1,1,2,5).
This input gives you five queries.

  • The first query changes A4A_4 to 33, making A=(2,0,2,3,1,1,2,5)A=(2,0,2,3,1,1,2,5).
    • At this point, the mex\rm{mex} of AA is 44.
  • The second query changes A4A_4 to 44, making A=(2,0,2,4,1,1,2,5)A=(2,0,2,4,1,1,2,5).
    • At this point, the mex\rm{mex} of AA is 33.
  • The third query changes A6A_6 to 33, making A=(2,0,2,4,1,3,2,5)A=(2,0,2,4,1,3,2,5).
    • At this point, the mex\rm{mex} of AA is 66.
  • The fourth query changes A8A_8 to 10000000001000000000, making A=(2,0,2,4,1,3,2,1000000000)A=(2,0,2,4,1,3,2,1000000000).
    • At this point, the mex\rm{mex} of AA is 55.
  • The fifth query changes A2A_2 to 11, making A=(2,1,2,4,1,3,2,1000000000)A=(2,1,2,4,1,3,2,1000000000).
    • At this point, the mex\rm{mex} of AA is 00.

update @ 2024/3/10 01:14:12