题库练习 Mark and Professor Koro
← 上一题 下一题 →

A15199 | Mark and Professor Koro

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 $n$ positive integers $a_1, a_2,\dots,a_n$ on it.

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

- select an integer $x$ that appears at least $2$ times on the board,
- erase those $2$ appearances, and
- write $x+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 $q$ times. Each time, he will choose positive integers $k$ and $l$ , then change $a_k$ to $l$ . 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 $a$ will apply when processing future updates.

输入格式

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

The second line contains $n$ integers $a_1,a_2,\dots,a_n$ ( $1\leq a_i\leq 2\cdot 10^5$ )

Then, $q$ lines follow, each consisting of two integers $k$ and $l$ ( $1\leq k\leq n$ , $1\leq l\leq 2\cdot 10^5$ ), telling to update $a_k$ to $l$ .

输出格式

Print $q$ lines. The $i$ -th line should consist of a single integer — the answer after the $i$ -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
C++ 编辑器
输入
输出