继续屯板子
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 200010
using namespace std;
int sz[N],fa[N],pf[N],ch[N][2],rev[N];
inline int gw(int x)
{
return ch[fa[x]][1]==x;
}
inline int push_down(int x)
{
if(!rev[x]) return 0;
swap(ch[x][0],ch[x][1]);
if(ch[x][0]) rev[ch[x][0]]^=1;
if(ch[x][1]) rev[ch[x][1]]^=1;
return rev[x]=0;
}
inline int push_up(int x)
{
return sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;
}
inline int setc(int x,int y,int z)
{
if(!x) return fa[y]=0;
ch[x][z]=y;if(y) fa[y]=x;
return push_up(x);
}
inline int rotate(int x)
{
int y=fa[x],z=fa[y],a=gw(x),b=gw(y),c=ch[x][a^1];
return swap(pf[x],pf[y]),setc(y,c,a),setc(x,y,a^1),setc(z,x,b);
}
int all_down(int x)
{
if(fa[x]) all_down(fa[x]);
if(rev[x]) push_down(x);
return 0;
}
inline int splay(int x)
{
all_down(x);
while(fa[x])
{
if(fa[fa[x]])
{
if(gw(x)^gw(fa[x])) rotate(x);
else rotate(fa[x]);
}
rotate(x);
}
return 0;
}
inline int expose(int x)
{
splay(x);int c=ch[x][1];
if(c) fa[c]=ch[x][1]=0,pf[c]=x;
return push_up(x);
}
inline bool splice(int x)
{
splay(x);int y=pf[x];if(!y) return false;
expose(y),splay(y),setc(y,x,1),pf[x]=0;
return true;
}
inline int access(int x)
{
expose(x);while(splice(x));return 0;
}
inline int evert(int x)
{
return access(x),splay(x),rev[x]^=1;
}
inline int link(int x,int y)
{
return evert(y),splay(y),pf[y]=x;
}
inline int cut(int x,int y)
{
evert(x),access(y),splay(x);
ch[x][1]=fa[y]=pf[y]=0;
return push_up(x);
}
#define gc getchar()
inline int inn()
{
int x,ch;while((ch=gc)<'0'||ch>'9');
x=ch^'0';while((ch=gc)>='0'&&ch<='9')
x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int a[N];
int main()
{
int n=inn();
for(int i=1;i<=n+1;i++) sz[i]=1;
for(int i=1;i<=n;i++)
link(i,a[i]=min(inn()+i,n+1));
int m=inn(),x,y;
while(m--)
{
if(inn()==1) x=inn()+1,evert(n+1),access(x),splay(x),printf("%d\n",sz[x]-1);
else x=inn()+1,y=inn(),cut(x,a[x]),link(x,a[x]=min(x+y,n+1));
}
return 0;
}