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 ai). If you throw a ball into hole i it will immediately jump to hole i + ai, 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 ≤ 105, 1 ≤ M ≤ 105) — 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
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.
8 5 1 1 1 1 1 2 8 2 1 1 0 1 3 1 1 0 3 4 1 2
8 7 8 5 7 3
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100010;
typedef long long ll;
int st[maxn],next[maxn],ed[maxn],po[maxn];
int block,n,m,ans,ansp;
void update(int x,int y)
{
if(y>n)
ed[x]=x,st[x]=1,next[x]=y;
else
{
ed[x]=ed[y];//ed[x]为从x处放球的终点
if(x/block==y/block)
next[x]=next[y],st[x]=st[y]+1;//next[i]表示i跳到另外的块的位置
else
next[x]=y,st[x]=1;
}
}
void qu(int x)
{
ans=0;
while(1)
{
ans+=st[x];
if(next[x]>n)
{
ansp=ed[x];
break;
}
x=next[x];
}
}
int main()
{
int i,cmd,a,b;
while(~scanf("%d%d",&n,&m))
{
block=ceil(sqrt(1.0*n));
for(i=1;i<=n;i++)
scanf("%d",&po[i]);
for(i=n;i>=1;i--)
update(i,i+po[i]);
while(m--)
{
scanf("%d%d",&cmd,&a);
if(cmd)
{
qu(a);
printf("%d %d\n",ansp,ans);
}
else
{
scanf("%d",&po[a]);
b=(a/block)*block;
b=max(b,1);
for(i=a;i>=b;i--)
update(i,i+po[i]);
}
}
}
return 0;
}