# bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 -- LCT

## 2002: [Hnoi2010]Bounce 弹飞绵羊

Time Limit: 10 Sec  Memory Limit: 259 MB

4
1 2 1 1
3
1 1
2 1 1
1 1

2
3

## HINT

LCT入门题

#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 1000000007
#define ll long long
#define N 200010
inline int rd()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
int nxt[N],c[N][2],fa[N],sz[N],st[N];
bool rev[N];
#define ls c[x][0]
#define rs c[x][1]
inline bool isrt(int x){return c[fa[x]][0]!=x&&c[fa[x]][1]!=x;}
inline void pd(int x)
{
if(!rev[x]) return;
rev[ls]^=1;rev[rs]^=1;
swap(ls,rs);rev[x]=0;
}
inline void upd(int x){sz[x]=sz[ls]+sz[rs]+1;}
void rot(int x)
{
int y=fa[x],z=fa[y],l,r;
l=c[y][1]==x;r=l^1;
if(!isrt(y)) c[z][c[z][1]==y]=x;
fa[x]=z;fa[y]=x;fa[c[x][r]]=y;
c[y][l]=c[x][r];c[x][r]=y;
upd(x);upd(y);
}
void splay(int x)
{
int tt=1,y,z;st[1]=x;
for(int i=x;!isrt(i);i=fa[i]) st[++tt]=fa[i];
for(int i=tt;i;i--) pd(st[i]);
while(!isrt(x))
{
y=fa[x];z=fa[y];
if(!isrt(y))
{
if(c[y][0]==x^c[z][0]==y) rot(x);
else rot(y);
}
rot(x);
}
}
void acc(int x)
{
int t=0;
while(x)
{
splay(x);
rs=t;
t=x;x=fa[x];
}
}
void rever(int x)
{
acc(x);splay(x);
rev[x]^=1;
}
void cut(int x,int y)
{
rever(x);acc(y);
splay(y);c[y][0]=fa[x]=0;
}
{
rever(x);fa[x]=y;
splay(x);
}
int main()
{
n=rd();
for(int i=1,x;i<=n;i++)
{
x=rd();
fa[i]=x+i;sz[i]=1;
if(fa[i]>n+1) fa[i]=n+1;
nxt[i]=fa[i];
}
sz[n+1]=1;
m=rd();
int op,x,y,t;
while(m--)
{
op=rd();
if(op==1)
{
rever(n+1);
x=rd()+1;
acc(x);splay(x);
printf("%d\n",sz[ls]);
}
else
{
x=rd()+1;y=rd();
t=min(n+1,x+y);