CF625E.Frog Fights
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ostap Bender recently visited frog farm and was inspired to create his own frog game.
Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for a__i cells.
Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves a__i cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value a__i is decreased by the number of frogs that were knocked out during this turn. If a__i is zero or goes negative, then i-th frog doesn't make moves anymore.
After frog number 1 finishes its turn, frog number 2 starts to move, then frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
Help Ostap to identify, what frogs will stay on the board at the end of a game?
奥斯塔普·本德尔最近参观了一家青蛙农场,并由此获得灵感,设计了自己的青蛙游戏。
若干只青蛙被放置在一个环形游戏板上,该棋盘被划分为 m 个格子。格子编号为 1 到 m,但由于棋盘是环形的,因此在移动方向上,编号为 1 的格子紧接在编号为 m 的格子之后。第 i 只青蛙在自己的回合中可以向前跳跃 ai 个格子。
青蛙按顺序轮流行动,游戏由第 1 只青蛙率先开始。在第 i 只青蛙的回合中,它向前移动 ai 个格子,并将其路径上的所有青蛙全部“击出”(即移出棋盘)。若第 i 只青蛙跳跃路径的终点格子上恰好存在另一只青蛙,则该青蛙同样被击出。随后,将 ai 的值减去本轮中被击出的青蛙数量。若 ai 变为零或负数,则第 i 只青蛙此后不再进行任何移动。
当第 1 只青蛙完成其回合后,第 2 只青蛙开始行动;接着是第 3 只青蛙,依此类推。当第 n 只青蛙完成其回合后,再次轮到第 1 只青蛙行动,然后是第 2 只青蛙……如此循环往复,永不停止。若某只青蛙已被击出棋盘,则视为它跳过所有属于自己的回合。
请帮助奥斯塔普判断:游戏最终结束时,哪些青蛙仍留在棋盘上?
输入格式
First line of the input contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 109, n ≤ m) — number of frogs and gameboard size, respectively.
Following n lines contains frogs descriptions — two integers p__i and a__i (1 ≤ p__i, a__i ≤ m) — the number of cell occupied by i-th frog initially and initial jump length. All p__i are guaranteed to be distinct.
输入的第一行包含两个整数 n 和 m(1 ≤ n ≤ 100000,1 ≤ m ≤ 109,n ≤ m),分别表示青蛙的数量和游戏板的大小。
接下来的 n 行描述了每只青蛙的信息——每行包含两个整数 pi 和 ai(1 ≤ pi, ai ≤ m),分别表示第 i 只青蛙初始所处的格子编号及其初始跳跃长度。所有 pi 保证互不相同。
输出格式
In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.
第一行输出最终游戏板上青蛙的数量。
第二行以任意顺序输出它们的编号。
输入输出样例
输入#1
3 5 2 1 5 3 4 3
输出#1
1 3
输入#2
5 6 1 2 3 4 2 5 5 1 6 1
输出#2
2 1 4
说明/提示
In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it's the only remaining frog in the game.
In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value a__i is now 0. Then fourth frog jumps and knocks out fifth frog and its a__i is now 0 too. These two frogs will remains on the gameboard forever.
在第一个样例中,第一只青蛙跳跃 1 格,最终落在编号为 3 的格子上;第二只青蛙跳跃 3 格,最终也落在编号为 3 的格子上,从而将编号为 1 的青蛙踢出游戏板。此时,编号为 2 的青蛙的当前跳跃长度变为 2。第三只青蛙跳至编号为 2 的格子,随后第二只青蛙跳至编号为 5 的格子;接着第三只青蛙也跳至编号为 5 的格子,并将编号为 2 的青蛙从游戏板上移除。此时,它是游戏中唯一剩下的青蛙。
在第二个样例中,第一只青蛙跳跃 2 格,将位于编号为 2 和 3 的格子上的青蛙全部踢出;其数值 ai 变为 0。随后,第四只青蛙跳跃,并将第五只青蛙踢出,其 ai 也变为 0。这两只青蛙将永远停留在游戏板上。
输入解题思路,AI测评打分。不知道怎么写?