Description

某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系数ki,当绵羊达到第i个装置时,它会往后弹ki步,达到第i+ki个装置,若不存在第i+ki个装置,则绵羊被弹飞。绵羊想知道当它从第i个装置起步时,被弹几次后会被弹飞。为了使得游戏更有趣,Lostmonkey可以修改某个弹力装置的弹力系数,任何时候弹力系数均为正整数。
Input

第一行包含一个整数n,表示地上有n个装置,装置的编号从0到n-1,接下来一行有n个正整数,依次为那n个装置的初始弹力系数。第三行有一个正整数m,接下来m行每行至少有两个数i、j,若i=1,你要输出从j出发被弹几次后被弹飞,若i=2则还会再输入一个正整数k,表示第j个弹力装置的系数被修改成k。对于20%的数据n,m<=10000,对于100%的数据n<=200000,m<=100000
Output

对于每个i=1的情况,你都要输出一个需要的步数,占一行。
Sample Input
4
1 2 1 1
3
1 1
2 1 1
1 1
Sample Output
2
3

入门级link-cut-tree

跟树链剖分很像,不过树链剖分形态不能变,直接把链分好了,然后用线段树维护这些链

这个link-cut-tree的主要操作是access(x),表示访问x节点

规则是每次访问x后从x到根节点的路径变成一条链,把这条链上长出来的枝叶减掉,链在不断地变化,所以用splay维护这个链

对于这个改变父节点,就是先断开他与父节点的链,然后接上他现在的父节点

这个讲的比较详细,可以看一下,http://hi.baidu.com/niyuzheno1/item/30994f43ba02c8c31e19bc28

 const
maxn=;
type
node=record
son:array[..]of longint;
size,fa:longint;
root:boolean;
end;
var
tree:array[..maxn]of node;
n,m:longint; procedure rotate(x,w:longint);
var
y:longint;
begin
y:=tree[x].fa;
tree[y].son[w]:=tree[x].son[w xor ];
if tree[x].son[w xor ]<> then tree[tree[x].son[w xor ]].fa:=y;
tree[x].son[w xor ]:=y;
if tree[y].root then
begin
tree[y].root:=false;
tree[x].root:=true;
end
else
if tree[tree[y].fa].son[]=y then tree[tree[y].fa].son[]:=x
else tree[tree[y].fa].son[]:=x;
tree[x].fa:=tree[y].fa;
tree[y].fa:=x;
tree[y].size:=tree[tree[y].son[]].size+tree[tree[y].son[]].size+;
end; procedure splay(x:longint);
var
y:longint;
begin
while tree[x].root=false do
begin
y:=tree[x].fa;
if tree[y].root then
if tree[y].son[]=x then rotate(x,)
else rotate(x,)
else
if tree[tree[y].fa].son[]=y then
if tree[y].son[]=x then
begin
rotate(y,);
rotate(x,);
end
else
begin
rotate(x,);
rotate(x,);
end
else
if tree[y].son[]=x then
begin
rotate(x,);
rotate(x,);
end
else
begin
rotate(y,);
rotate(x,);
end;
end;
tree[x].size:=tree[tree[x].son[]].size+tree[tree[x].son[]].size+;
end; procedure access(x:longint);
var
z:longint;
begin
splay(x);
while tree[x].fa<> do
begin
z:=tree[x].fa;
splay(z);
tree[tree[z].son[]].root:=true;
tree[x].root:=false;
tree[z].son[]:=x;
tree[z].size:=tree[tree[z].son[]].size+tree[tree[z].son[]].size+;
splay(x);
end;
end; procedure init;
var
i:longint;
begin
read(n);
for i:= to n do
begin
tree[i].root:=true;
tree[i].size:=;
read(tree[i].fa);
inc(tree[i].fa,i);
if tree[i].fa>n then tree[i].fa:=n+;
end;
tree[n+].size:=;
tree[n+].root:=true;
end; procedure work;
var
i,x,y:longint;
begin
read(m);
for i:= to m do
begin
read(x,y);
inc(y);
if x= then
begin
access(y);
writeln(tree[tree[y].son[]].size);
end
else
begin
read(x);
splay(y);
tree[tree[y].son[]].fa:=tree[y].fa;
tree[tree[y].son[]].root:=true;
tree[y].son[]:=;
tree[y].size:=tree[tree[y].son[]].size+;
tree[y].fa:=y+x;
if tree[y].fa>n then tree[y].fa:=n+;
end;
end;
end; begin
init;
work;
end.

2002: [Hnoi2010]Bounce 弹飞绵羊 - BZOJ的更多相关文章

  1. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 9071  Solved: 4652[Submi ...

  2. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  3. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 LCT

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  4. bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 4055  Solved: 2172[Submi ...

  5. bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...

  6. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (动态树LCT)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2843  Solved: 1519[Submi ...

  7. 【BZOJ】2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 14802  Solved: 7507[Subm ...

  8. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 ...

  9. 2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 https://www.lydsy.com/JudgeOnline/problem.php?id=2002 分析: 绵羊在弹飞的路径中相当于一棵 ...

随机推荐

  1. Windows 7 IE11 F12 不能正常使用

    打开任意网站,按下F12,或者右键鼠标,按L键.出现上面的图的情况!解决办法如下:需要安装下面的补丁(KB3008923) 32位系统:http://www.microsoft.com/en-us/d ...

  2. Git CMD - reset: Reset current HEAD to the specified state

    命令格式 git reset [-q] [<tree-ish>] [--] <paths>…​ git reset (--patch | -p) [<tree-ish&g ...

  3. Git CMD - remote: Manage set of tracked repositories

    命令格式 git remote [-v | --verbose] git remote add [-t <branch>] [-m <master>] [-f] [--[no- ...

  4. rowid

    rowid:select t.*,t.rowid from test t; -- AACeJKAAIAAAA4XAAA 注:有个很二需求,通过一个存储过程插入的数据必须是放在一块的,不能分散开存储,考 ...

  5. HTML+CSS学习笔记(5)- 与浏览者交互,表单标签

    HTML+CSS学习笔记(5)- 与浏览者交互,表单标签 1.使用表单标签,与用户交互 网站怎样与用户进行交互?答案是使用HTML表单(form).表单是可以把浏览者输入的数据传送到服务器端,这样服务 ...

  6. jquery实现2级联动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Junit的最简单样例:Hello world!

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3824934.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  8. 利用多核来加速Linux命令行

    本文转载自 多核CPU来加速 awk, sed, bzip2, grep, wc等,如需查看原文,请点此链接进入. -------------------------------我是分割线 开始 -- ...

  9. JSONP VS CORS

    What is JSONP ? http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about What is CORS? htt ...

  10. jQuery 全选 反选 单击行改变背景色

    我先把CSS样式放出来,其实这个可以直接忽略 ;;font-size:12px;font-family:微软雅黑;} .datagrid{width:100%;} .datagird tr th{ba ...