A7767 | Holes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:
There are $N$ holes located in a single row and numbered from left to right with numbers from 1 to $N$ . Each hole has it's own power (hole number $i$ has the power $a_{i}$ ). If you throw a ball into hole $i$ it will immediately jump to hole $i+a_{i}$ , then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of the $M$ moves the player can perform one of two actions:
- Set the power of the hole $a$ to value $b$ .
- Throw a ball into the hole $a$ and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row.
Petya is not good at math, so, as you have already guessed, you are to perform all computations.
There are $N$ holes located in a single row and numbered from left to right with numbers from 1 to $N$ . Each hole has it's own power (hole number $i$ has the power $a_{i}$ ). If you throw a ball into hole $i$ it will immediately jump to hole $i+a_{i}$ , then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of the $M$ moves the player can perform one of two actions:
- Set the power of the hole $a$ to value $b$ .
- Throw a ball into the hole $a$ and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row.
Petya is not good at math, so, as you have already guessed, you are to perform all computations.
输入格式
The first line contains two integers $N$ and $M$ ( $1<=N<=10^{5}$ , $1<=M<=10^{5}$ ) — the number of holes in a row and the number of moves. The second line contains $N$ positive integers not exceeding $N$ — initial values of holes power. The following $M$ lines describe moves made by Petya. Each of these line can be one of the two types:
- $0$ $a$ $b$
- $1$ $a$
Type $0$ means that it is required to set the power of hole $a$ to $b$ , and type $1$ means that it is required to throw a ball into the $a$ -th hole. Numbers $a$ and $b$ are positive integers do not exceeding $N$ .
- $0$ $a$ $b$
- $1$ $a$
Type $0$ means that it is required to set the power of hole $a$ to $b$ , and type $1$ means that it is required to throw a ball into the $a$ -th hole. Numbers $a$ and $b$ are positive integers do not exceeding $N$ .
输出格式
For each move of the type $1$ output two space-separated numbers on a separate line — the number of the last hole the ball visited before leaving the row and the number of jumps it made.
输入输出样例
输入 #1
8 5 1 1 1 1 1 2 8 2 1 1 0 1 3 1 1 0 3 4 1 2
输出 #1
8 7 8 5 7 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted