## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Mark and Professor Koro Codeforces Solution

E. Mark and Professor Koro
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Solution Click Below:-  👉
👇👇👇👇👇

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

Mark and the Online Exam Codeforces Solution

Mark and Professor Koro Codeforces Solution

Mark and Lightbulbs Codeforces Solution

Mark and His Unfinished Essay Codeforces Solution

Mark the Dust Sweeper Codeforces Solution

Mark the Photographer Codeforces Solution

Input

The first line of the input contains two integers $n$ and $q$ ($2\le n\le 2\cdot {10}^{5}$$1\le q\le 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\le {a}_{i}\le 2\cdot {10}^{5}$)

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

Output

Print $q$ lines. The $i$-th line should consist of a single integer — the answer after the $i$-th update.