CF1705E.Mark and Professor Koro

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After watching a certain anime before going to sleep, Mark dreams of standing in an old classroom with a blackboard that has a sequence of nn positive integers a1,a2,,ana_1, a_2,\dots,a_n on it.

Then, professor Koro comes in. He can perform the following operation:

  • select an integer xx that appears at least 22 times on the board,
  • erase those 22 appearances, and
  • write x+1x+1 on the board.

Professor Koro then asks Mark the question, "what is the maximum possible number that could appear on the board after some operations?"

Mark quickly solves this question, but he is still slower than professor Koro. Thus, professor Koro decides to give Mark additional challenges. He will update the initial sequence of integers qq times. Each time, he will choose positive integers kk and ll , then change aka_k to ll . After each update, he will ask Mark the same question again.

Help Mark answer these questions faster than Professor Koro!

Note that the updates are persistent. Changes made to the sequence aa will apply when processing future updates.

输入格式

The first line of the input contains two integers nn and qq ( 2n21052\leq n\leq 2\cdot 10^5 , 1q21051\leq q\leq 2\cdot 10^5 ) — the length of the sequence aa and the number of updates, respectively.

The second line contains nn integers a1,a2,,ana_1,a_2,\dots,a_n ( 1ai21051\leq a_i\leq 2\cdot 10^5 )

Then, qq lines follow, each consisting of two integers kk and ll ( 1kn1\leq k\leq n , 1l21051\leq l\leq 2\cdot 10^5 ), telling to update aka_k to ll .

输出格式

Print qq lines. The ii -th line should consist of a single integer — the answer after the ii -th update.

输入输出样例

  • 输入#1

    5 4
    2 2 2 4 5
    2 3
    5 3
    4 1
    1 4

    输出#1

    6
    5
    4
    5
  • 输入#2

    2 1
    200000 1
    2 200000

    输出#2

    200001

说明/提示

In the first example test, the program must proceed through 44 updates.

The sequence after the first update is [2,3,2,4,5][2,3,2,4,5] . One sequence of operations that achieves the number 66 the following.

  • Initially, the blackboard has numbers [2,3,2,4,5][2,3,2,4,5] .
  • Erase two copies of 22 and write 33 , yielding [3,4,5,3][3,4,5,\color{red}{3}] .
  • Erase two copies of 33 and write 44 , yielding [4,5,4][4,5,\color{red}{4}] .
  • Erase two copies of 44 and write 55 , yielding [5,5][5,\color{red}{5}] .
  • Erase two copies of 55 and write 66 , yielding [6][\color{red}{6}] .

Then, in the second update, the array is changed to [2,3,2,4,3][2,3,2,4,3] . This time, Mark cannot achieve 66 . However, one sequence that Mark can use to achieve 55 is shown below.

  • Initially, the blackboard has [2,3,2,4,3][2,3,2,4,3] .
  • Erase two copies of 22 and write 33 , yielding [3,4,3,3][3,4,3,\color{red}{3}] .
  • Erase two copies of 33 and write 44 , yielding [3,4,4][3,4,\color{red}{4}] .
  • Erase two copies of 44 and write 55 , yielding [3,5][3,\color{red}{5}] .

In the third update, the array is changed to [2,3,2,1,3][2,3,2,1,3] . One way to achieve 44 is shown below.

  • Initially, the blackboard has [2,3,2,1,3][2,3,2,1,3] .
  • Erase two copies of 33 and write 44 , yielding [2,2,1,4][2,2,1,\color{red}{4}] .
首页