传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=2002
题目大意
支持删边同时添边+查询深度
题解
LCT模板题
写了之后才发现细节满满
const
maxn=200005;
var
root,fa,size:array[0..maxn]of longint;
son:array[0..maxn,1..2]of longint;
i,j,k:longint;
n,m,len,a,b,c:longint;
function min(a,b:longint):longint;
begin if a>b then exit(b) else exit(a); end;
procedure rotate(a,kind:longint);
var b,unkind:longint;
begin
b:=fa[a]; unkind:=kind xor 3;
son[b,kind]:=son[a,unkind]; fa[son[b,kind]]:=b; son[a,unkind]:=b;
if son[fa[b],1]=b then son[fa[b],1]:=a else
if son[fa[b],2]=b then son[fa[b],2]:=a;
fa[a]:=fa[b]; fa[b]:=a;
root[a]:=root[a] xor root[b];
root[b]:=root[a] xor root[b];
size[b]:=size[son[b,1]]+size[son[b,2]]+1;
size[a]:=size[son[a,1]]+size[son[a,2]]+1;
end;
procedure splay(a:longint);
var b,kind,unkind:longint;
begin
while root[a]=0 do
begin
b:=fa[a]; if son[b,1]=a then kind:=1 else kind:=2; unkind:=kind xor 3;
if root[b]=1 then rotate(a,kind)
else
if son[fa[b],kind]=b
then begin rotate(b,kind); rotate(a,kind); end
else begin rotate(a,kind); rotate(a,unkind); end;
end;
end;
procedure access(a:longint);
var b:longint;
begin
splay(a);
while fa[a]<>0 do
begin
splay(fa[a]);
b:=fa[a];
root[son[b,2]]:=1; root[a]:=0;
son[b,2]:=a; size[b]:=size[son[b,1]]+size[son[b,2]]+1;
splay(a);
end;
end;
begin
readln(n);
for i:=1 to n do
begin read(a); fa[i]:=min(a+i,n+1); end;
for i:=1 to n+1 do
size[i]:=1;
for i:=1 to n+1 do
root[i]:=1;
readln(m);
for i:=1 to m do
begin
read(a);
if a=1
then
begin
readln(b); inc(b);
access(b);
writeln(size[son[b,1]]);
end
else
begin
readln(b,c); inc(b);
splay(b);
fa[son[b,1]]:=fa[b];
root[son[b,1]]:=1;
son[b,1]:=0; size[b]:=size[son[b,2]]+1;
fa[b]:=min(b+c,n+1);
end;
end;
end.