#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxl 200010
using namespace std;
int n,m,cnt,size;
int a[maxl],l[maxl],r[maxl],times[maxl],nxtpos[maxl],pos[maxl];
void prework()
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
size=sqrt(n);cnt=n/size;
if(n%size)
cnt++;
for(int i=1;i<=cnt;i++)
{
l[i]=(i-1)*size+1;r[i]=min(i*size,n);
for(int j=l[i];j<=r[i];j++)
pos[j]=i;
}
l[cnt+1]=n+1;r[cnt+1]=maxl-1;
for(int i=n;i>=1;i--)
{
times[i]=1;nxtpos[i]=i+a[i];
if(i+a[i]<=r[pos[i]])
times[i]=times[i+a[i]]+1,nxtpos[i]=nxtpos[i+a[i]];
}
}
void mainwork()
{
int opt,x,k,ans,d,now;
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&opt);
if(opt==1)
{
ans=0;
scanf("%d",&x);x++;
while(x<=n)
{
ans+=times[x];
x=nxtpos[x];
}
printf("%d\n",ans);
}
if(opt==2)
{
scanf("%d%d",&x,&k);x++;
a[x]=k;
d=x+a[x];times[x]=1;
while(d<l[pos[x]+1])
times[x]++,d=d+a[d];
nxtpos[x]=d;
for(int j=x-1;j>=l[pos[x]];j--)
if(j+a[j]<=r[pos[x]])
{
times[j]=1+times[j+a[j]];
nxtpos[j]=nxtpos[j+a[j]];
}
}
}
}
int main()
{
while(~scanf("%d",&n))
{
prework();
mainwork();
}
return 0;
}
BZOJ2002
最新推荐文章于 2021-05-06 21:29:11 发布