CF1705E.Mark and Professor Koro

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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.

睡前观看某部动漫后,马克梦见自己站在一间古老的教室里,黑板上写着一个由 nn 个正整数 a1,a2,…,ana_1, a_2,\dots,a_n 构成的序列。

接着,Koro 教授走了进来。他可以执行如下操作:

  • 选择一个在黑板上至少出现两次的整数 xx,
  • 擦去该整数的两个出现,
  • 在黑板上写下 x+1x+1。

随后,Koro 教授向马克提问:“经过若干次操作后,黑板上可能出现的最大数字是多少?”

马克很快便解答了这个问题,但他的速度仍不及 Koro 教授。于是,Koro 教授决定给马克增设额外挑战:他将对初始整数序列进行 qq 次更新。每次更新中,他选择正整数 kk 和 ll,并将 aka_k 修改为 ll。每次更新后,他都会再次向马克提出相同的问题。

请帮助马克比 Koro 教授更快地回答这些问题!

注意:这些更新是持久化的。对序列 aa 所做的修改将在后续所有更新中持续生效。

输入格式

The first line of the input contains two integers nn and qq (2≤n≤2⋅1052\leq n\leq 2\cdot 10^5, 1≤q≤2⋅1051\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 (1≤ai≤2⋅1051\leq a_i\leq 2\cdot 10^5)

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

输入的第一行包含两个整数 nn 和 qq(2≤n≤2⋅1052\leq n\leq 2\cdot 10^5,1≤q≤2⋅1051\leq q\leq 2\cdot 10^5),分别表示序列 aa 的长度和更新操作的次数。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\dots,a_n(1≤ai≤2⋅1051\leq a_i\leq 2\cdot 10^5)。

接下来是 qq 行,每行包含两个整数 kk 和 ll(1≤k≤n1\leq k\leq n,1≤l≤2⋅1051\leq l\leq 2\cdot 10^5),表示将 aka_k 更新为 ll。

输出格式

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

输出 qq 行。第 ii 行应包含一个整数——即第 ii 次更新后的答案。

输入输出样例

  • 输入#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}].

在第一个样例测试中,程序必须执行 44 次更新。

第一次更新后的序列为 [2,3,2,4,5][2,3,2,4,5]。以下是一组可得到数字 66 的操作序列:

  • 最初,黑板上的数字为 [2,3,2,4,5][2,3,2,4,5]。
  • 擦除两个 22 并写入 33,得到 [3,4,5,3][3,4,5,\color{red}{3}]。
  • 擦除两个 33 并写入 44,得到 [4,5,4][4,5,\color{red}{4}]。
  • 擦除两个 44 并写入 55,得到 [5,5][5,\color{red}{5}]。
  • 擦除两个 55 并写入 66,得到 [6][\color{red}{6}]。

接着,在第二次更新中,数组变为 [2,3,2,4,3][2,3,2,4,3]。此时,Mark 无法得到 66。但 Mark 可以通过如下操作序列得到 55:

  • 最初,黑板上的数字为 [2,3,2,4,3][2,3,2,4,3]。
  • 擦除两个 22 并写入 33,得到 [3,4,3,3][3,4,3,\color{red}{3}]。
  • 擦除两个 33 并写入 44,得到 [3,4,4][3,4,\color{red}{4}]。
  • 擦除两个 44 并写入 55,得到 [3,5][3,\color{red}{5}]。

在第三次更新中,数组变为 [2,3,2,1,3][2,3,2,1,3]。一种可得到 44 的方法如下所示:

  • 最初,黑板上的数字为 [2,3,2,1,3][2,3,2,1,3]。
  • 擦除两个 33 并写入 44,得到 [2,2,1,4][2,2,1,\color{red}{4}]。

输入解题思路,AI测评打分。不知道怎么写?

首页