A9894 | Case of a Top Secret
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Andrewid the Android is a galaxy-famous detective. Now he is busy with a top secret case, the details of which are not subject to disclosure.
However, he needs help conducting one of the investigative experiment. There are $n$ pegs put on a plane, they are numbered from $1$ to $n$ , the coordinates of the $i$ -th of them are $(x_{i},0)$ . Then, we tie to the bottom of one of the pegs a weight on a tight rope of length $l$ (thus, its coordinates will be equal to $(x_{i},-l)$ , where $i$ is the number of the used peg). Then the weight is pushed to the right, so that it starts to rotate counterclockwise. At the same time, if the weight during rotation touches some of the other pegs, it then begins to rotate around that peg. Suppose that each peg itself is very thin and does not affect the rope length while weight is rotating around it.
More formally, if at some moment the segment of the rope contains one or more pegs in addition to the peg around which the weight is rotating, the weight will then rotate around the farthermost one of them on a shorter segment of a rope. In particular, if the segment of the rope touches some peg by its endpoint, it is considered that the weight starts to rotate around that peg on a segment of the rope of length $0$ .
At some moment the weight will begin to rotate around some peg, without affecting the rest of the pegs. Andrewid interested in determining the number of this peg.
Andrewid prepared $m$ queries containing initial conditions for pushing the weight, help him to determine for each of them, around what peg the weight will eventually rotate.
However, he needs help conducting one of the investigative experiment. There are $n$ pegs put on a plane, they are numbered from $1$ to $n$ , the coordinates of the $i$ -th of them are $(x_{i},0)$ . Then, we tie to the bottom of one of the pegs a weight on a tight rope of length $l$ (thus, its coordinates will be equal to $(x_{i},-l)$ , where $i$ is the number of the used peg). Then the weight is pushed to the right, so that it starts to rotate counterclockwise. At the same time, if the weight during rotation touches some of the other pegs, it then begins to rotate around that peg. Suppose that each peg itself is very thin and does not affect the rope length while weight is rotating around it.
More formally, if at some moment the segment of the rope contains one or more pegs in addition to the peg around which the weight is rotating, the weight will then rotate around the farthermost one of them on a shorter segment of a rope. In particular, if the segment of the rope touches some peg by its endpoint, it is considered that the weight starts to rotate around that peg on a segment of the rope of length $0$ .
At some moment the weight will begin to rotate around some peg, without affecting the rest of the pegs. Andrewid interested in determining the number of this peg.
Andrewid prepared $m$ queries containing initial conditions for pushing the weight, help him to determine for each of them, around what peg the weight will eventually rotate.
输入格式
The first line contains integers $n$ and $m$ ( $1<=n,m<=2·10^{5}$ ) — the number of pegs and queries.
The next line contains $n$ integers $x_{1},x_{2},...,x_{n}$ ( $-10^{9}<=x_{i}<=10^{9}$ ) — the coordinates of the pegs. It is guaranteed that the coordinates of all the pegs are distinct integers.
Next $m$ lines contain the descriptions of the queries of pushing the weight, each consists of two integers $a_{i}$ ( $1<=a_{i}<=n$ ) and $l_{i}$ ( $1<=l_{i}<=10^{9}$ ) — the number of the starting peg and the length of the rope.
The next line contains $n$ integers $x_{1},x_{2},...,x_{n}$ ( $-10^{9}<=x_{i}<=10^{9}$ ) — the coordinates of the pegs. It is guaranteed that the coordinates of all the pegs are distinct integers.
Next $m$ lines contain the descriptions of the queries of pushing the weight, each consists of two integers $a_{i}$ ( $1<=a_{i}<=n$ ) and $l_{i}$ ( $1<=l_{i}<=10^{9}$ ) — the number of the starting peg and the length of the rope.
输出格式
Print $m$ lines, the $i$ -th line should contain the number of the peg around which the weight will eventually rotate after the $i$ -th push.
输入输出样例
输入 #1
3 2 0 3 5 2 3 1 8
输出 #1
3 2
输入 #2
4 4 1 5 7 15 1 4 2 15 3 16 1 28
输出 #2
2 4 3 1
Picture to the first sample test:

Picture to the second sample test:

Note that in the last query weight starts to rotate around the peg 1 attached to a rope segment of length 0.

Picture to the second sample test:

Note that in the last query weight starts to rotate around the peg 1 attached to a rope segment of length 0.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted