CF1060G.Balls and Pockets
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a strip with an infinite number of cells. Cells are numbered starting with 0 . Initially the cell i contains a ball with the number i .
There are n pockets located at cells a1,…,an . Each cell contains at most one pocket.
Filtering is the following sequence of operations:
- All pockets at cells a1,…,an open simultaneously, which makes balls currently located at those cells disappear. After the balls disappear, the pockets close again.
- For each cell i from 0 to ∞ , if the cell i contains a ball, we move that ball to the free cell j with the lowest number. If there is no free cell j<i , the ball stays at the cell i .
Note that after each filtering operation each cell will still contain exactly one ball.
For example, let the cells 1 , 3 and 4 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 m questions. The i -th of these questions is "what is the number of the ball located at the cell xi after ki repetitions of the filtering operation?"
输入格式
The first line contains two integers n and m — the number of pockets and questions respectively ( 1≤n,m≤105 ).
The following line contains n integers a1,…,an — the numbers of cells containing pockets ( 0≤a1<…<an≤109 ).
The following m lines describe questions. The i -th of these lines contains two integers xi and ki ( 0≤xi,ki≤109 ).
输出格式
Print m numbers — answers to the questions, in the same order as given in the input.
输入输出样例
输入#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