早期的LCT简直无法直视OLZ…(我写的是splay时自顶向下一条路清标记的方法…
AC code:
#include <cstdio>
#include <stack>
using namespace std;
const int N=200010;
int n,m;
struct nod{
bool rev;
int size;
nod *ch[2],*pr,*pp;
}*NIL,pt[N],*tmp[N];
void clear(nod *x){
if(!x->rev) return ;
nod *t=x->ch[0];x->ch[0]=x->ch[1];x->ch[1]=t;
x->rev=0;x->ch[0]->rev^=1;x->ch[1]->rev^=1;
}
void update(nod *x){
x->size=x->ch[0]->size+x->ch[1]->size+1;
}
void rotate(nod *x,bool t){
nod *y=x->pr,*z=y->pr,*b=x->ch[t^1];
b->pr=y;y->pr=x;x->pr=z;y->ch[t]=b;x->ch[t^1]=y;
if(z->ch[0]==y) z->ch[0]=x;
else if(z->ch[1]==y) z->ch[1]=x;
update(y);update(x);
}
void splay(nod *x){
int tot=0;
nod *r=x;
for(nod *i=x;i!=NIL;i=i->pr) tmp[++tot]=i;
for(int i=tot;i>0;i--) clear(tmp[i]);
while(x->pr!=NIL){
nod *y=x->pr,*z=y->pr;
r=(z==NIL?y:z);
if(z==NIL&&y->ch[0]==x) rotate(x,0);
else if(z==NIL&&y->ch[1]==x) rotate(x,1);
else if(z->ch[0]==y&&y->ch[0]==x) {rotate(y,0);rotate(x,0);}
else if(z->ch[1]==y&&y->ch[1]==x) {rotate(y,1);rotate(x,1);}
else if(z->ch[1]==y&&y->ch[0]==x) {rotate(x,0);rotate(x,1);}
else {rotate(x,1);rotate(x,0);}
}
x->pp=r->pp;
}
void access(nod *x){
for(nod *u=x,*v=NIL;u!=NIL;v=u,u=u->pp)
{splay(u);u->ch[1]->pr=NIL;u->ch[1]->pp=u;u->ch[1]=v;v->pr=u;update(u);}
}
void link(nod *x,nod *y){
access(x);splay(x);x->pp=y;x->rev^=1;
}
void cut(nod *x){
access(x);splay(x);x->ch[0]->pr=x->ch[0]->pp=NIL;x->ch[0]=NIL;update(x);
}
int getdep(nod *x){
access(x);splay(x);
return x->ch[0]->size+1;
}
int main(){
NIL=&pt[N-1];
scanf("%d",&n);
for(int i=0;i<n;i++){
pt[i].size=1;
pt[i].ch[0]=pt[i].ch[1]=pt[i].pr=pt[i].pp=NIL;
}
for(int i=0;i<n;i++){
int k;
scanf("%d",&k);
if(i+k<n) link(&pt[i],&pt[i+k]);
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
int a,b,c;
scanf("%d%d",&a,&b);
if(a==1) printf("%d\n",getdep(&pt[b]));
else{
scanf("%d",&c);
cut(&pt[b]);
if(b+c<n) link(&pt[b],&pt[b+c]);
}
}
return 0;
}