LCT模板题
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define For(i,j,k) for(register int i=(j);i<=(int)k;i++)
#define Forr(i,j,k) for(register int i=(j);i>=(int)k;i--)
#define L(i) (T[(i)].s[0])
#define R(i) (T[(i)].s[1])
#define F(i) (T[(i)].fa)
#define Loc(i) (F(i)<0?0:(R(F(i))==i))
#define Set(a,b) memset((a),(b),sizeof(a))
using namespace std;
const int N=200010;
inline void read(int &x){
x=0;char c=getchar();int f=(c=='-');
while(c<'0'||c>'9')c=getchar(),f|=(c=='-');
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
}
struct node{
int s[2],fa,siz;
inline void init(){fa=s[0]=s[1]=0,siz=1;}
};
struct LCT{
node T[N];
inline void clear(int n){
For(i,0,n+1)T[i].init();
T[0].siz=0;
}
inline void maintain(int i){
T[i].siz=T[L(i)].siz+T[R(i)].siz+1;
}
inline void Sets(int a,int b,int c){
if (a>0)T[a].s[c]=b;
if (b>0)T[b].fa=a;
if (a>0)maintain(a);
}
inline void Rotate(int x){
int A=x,B=F(A),C=F(B),d=Loc(A),e=Loc(B);
Sets(B,T[A].s[d^1],d);
Sets(A,B,d^1);
Sets(C,A,e);
}
inline void splay(int x){
while(F(x)>0){
if(F(F(x))<=0)Rotate(x);
else Rotate(x),Rotate(x);
}
}
inline void access(int x){
splay(x);
while(F(x)<0){
int p=-F(x);
splay(p);
F(R(p))*=-1;
Sets(p,x,1);
splay(x);
}
}
inline int findrt(int x){
access(x);
while(L(x))x=L(x);
splay(x);
return x;
}
inline void link(int x,int y){
access(x);
F(x)=-y;
access(x);
}
inline void cut(int x){
access(x);
F(L(x))=0,L(x)=0;
}
}t;
int main(){
int n,m,x;
while(scanf("%d",&n)!=EOF){
t.clear(n);
For(i,1,n){
read(x);
if(i+x<=n)t.link(i,i+x);
}
scanf("%d",&m);
while(m--){
int tp,x,v;
read(tp);
if(tp-1){
read(x),read(v);x++;
t.cut(x);
if(x+v<=n)t.link(x,x+v);
}else {
read(x);x++;
t.access(x);
printf("%d\n",t.T[t.T[x].s[0]].siz+1);
}
}
}
return 0;
}