CF1060G.Balls and Pockets

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There is a strip with an infinite number of cells. Cells are numbered starting with 00. Initially the cell ii contains a ball with the number ii.

There are nn pockets located at cells a1,…,ana_1, \ldots, a_n. Each cell contains at most one pocket.

Filtering is the following sequence of operations:

  • All pockets at cells a1,…,ana_1, \ldots, a_n open simultaneously, which makes balls currently located at those cells disappear. After the balls disappear, the pockets close again.
  • For each cell ii from 00 to ∞\infty, if the cell ii contains a ball, we move that ball to the free cell jj with the lowest number. If there is no free cell j<ij \lt i, the ball stays at the cell ii.

Note that after each filtering operation each cell will still contain exactly one ball.

For example, let the cells 11, 33 and 44 contain pockets. The initial configuration of balls is shown below (underscores display the cells with pockets):

0 1 2 3 4 5 6 7 8 9 ...

After opening and closing the pockets, balls 1, 3 and 4 disappear:

0 2 5 6 7 8 9 ...

After moving all the balls to the left, the configuration looks like this:

0 2 5 6 7 8 9 10 11 12 ...

Another filtering repetition results in the following:

0 5 8 9 10 11 12 13 14 15 ...

You have to answer mm questions. The ii-th of these questions is "what is the number of the ball located at the cell xix_i after kik_i repetitions of the filtering operation?"

存在一条无限长的格子带,格子从 00 开始编号。初始时,格子 ii 中放置一个编号为 ii 的球。

有 nn 个口袋,分别位于格子 a1,…,ana_1, \ldots, a_n 处。每个格子至多包含一个口袋。

过滤操作(Filtering)定义为以下一系列步骤:

  • 所有位于格子 a1,…,ana_1, \ldots, a_n 的口袋同时打开,使得当前位于这些格子中的球立即消失;随后口袋关闭。
  • 对每个从 00 到 ∞\infty 的格子 ii:若格子 ii 中含有一个球,则将该球移动到编号最小的空闲格子 jj(即尚未被任何球占据的格子);若不存在满足 j<ij < i 的空闲格子,则该球保留在格子 ii 中。

注意:每次过滤操作后,每个格子仍恰好包含一个球。

例如,设口袋位于格子 11、33 和 44 处。初始球的分布如下(下划线标出含口袋的格子):

0 1 2 3 4 5 6 7 8 9 ...

口袋打开并关闭后,编号为 11、33、44 的球消失:

0 2 5 6 7 8 9 ...

将所有球向左移动至最近的空闲格子后,配置变为:

0 2 5 6 7 8 9 10 11 12 ...

再执行一次过滤操作,得到:

0 5 8 9 10 11 12 13 14 15 ...

你需要回答 mm 个询问。第 ii 个询问为:“经过 kik_i 次过滤操作后,位于格子 xix_i 的球的编号是多少?”

输入格式

The first line contains two integers nn and mm — the number of pockets and questions respectively (1≤n,m≤1051 \leq n, m \leq 10^5).

The following line contains nn integers a1,…,ana_1, \ldots, a_n — the numbers of cells containing pockets (0≤a1<…<an≤1090 \leq a_1 \lt \ldots \lt a_n \leq 10^9).

The following mm lines describe questions. The ii-th of these lines contains two integers xix_i and kik_i (0≤xi,ki≤1090 \leq x_i, k_i \leq 10^9).

第一行包含两个整数 nn 和 mm —— 分别表示口袋的数量和问题的数量(1≤n,m≤1051 \leq n, m \leq 10^5)。

接下来的一行包含 nn 个整数 a1,…,ana_1, \ldots, a_n —— 表示包含口袋的单元格编号(0≤a1<…<an≤1090 \leq a_1 \lt \ldots \lt a_n \leq 10^9)。

接下来的 mm 行描述了各个问题。其中第 ii 行包含两个整数 xix_i 和 kik_i(0≤xi,ki≤1090 \leq x_i, k_i \leq 10^9)。

输出格式

Print mm numbers — answers to the questions, in the same order as given in the input.

输出 mm 个数字——即对各个询问的回答,顺序与输入中给出的顺序一致。

输入输出样例

  • 输入#1

    3 15
    1 3 4
    0 0
    1 0
    2 0
    3 0
    4 0
    0 1
    1 1
    2 1
    3 1
    4 1
    0 2
    1 2
    2 2
    3 2
    4 2

    输出#1

    0
    1
    2
    3
    4
    0
    2
    5
    6
    7
    0
    5
    8
    9
    10

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

首页