LCT最基础的题,就用到了一个ACCESS操作

首先我们将这个绵羊弹飞的情况看成一颗树,那么假设X点被弹飞到

Y点,那么Y为X的父亲节点,弹飞的话父亲节点为n+1(虚设)

那么每个询问就是询问X点到根节点n+1的路径长度(节点数)

每个修改操作就是将以X为根节点的子树和X的父亲断开,连接到Y上

这样简单的维护森林连通性的问题,动态树中的LCT解决就行了

/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ //By BLADEVIL
var
n, m :longint;
father, size :array[-..] of longint;
son :array[-..,..] of longint;
root :array[-..] of boolean; procedure update(x:longint);
begin
size[x]:=size[son[x,]]+size[son[x,]]+;
end; procedure left_rotate(x:longint);
var
y :longint;
begin
y:=son[x,];
son[x,]:=son[y,];
father[son[x,]]:=x;
son[y,]:=x;
if x=son[father[x],] then
son[father[x],]:=y else
if x=son[father[x],] then
son[father[x],]:=y;
father[y]:=father[x];
father[x]:=y;
root[y]:=root[x] xor root[y];
root[x]:=root[x] xor root[y];
update(x); update(y);
end; procedure right_rotate(x:longint);
var
y :longint;
begin
y:=son[x,];
son[x,]:=son[y,];
father[son[x,]]:=x;
son[y,]:=x;
if x=son[father[x],] then
son[father[x],]:=y else
if x=son[father[x],] then
son[father[x],]:=y;
father[y]:=father[x];
father[x]:=y;
root[y]:=root[y] xor root[x];
root[x]:=root[y] xor root[x];
update(x); update(y);
end; procedure splay(x:longint);
begin
while not root[x] do
if x=son[father[x],] then
left_rotate(father[x]) else
right_rotate(father[x]);
end; procedure access(x:longint);
var
y :longint;
begin
splay(x);
while father[x]<> do
begin
y:=father[x];
splay(y);
root[son[y,]]:=true;
root[x]:=false;
son[y,]:=x;
update(y);
splay(x);
end;
end; procedure init;
var
i :longint;
begin
read(n);
for i:= to n do
begin
read(father[i]);
father[i]:=father[i]+i;
if father[i]>n then father[i]:=n+;
end;
read(m);
end; procedure main;
var
i :longint;
x, y, z :longint;
begin
for i:= to n+ do size[i]:=;
fillchar(root,sizeof(root),true);
for i:= to m do
begin
read(x);
if x= then
begin
read(y); inc(y);
access(y);
writeln(size[son[y,]]);
end else
begin
read(y,z); inc(y);
splay(y);
father[son[y,]]:=father[y];
root[son[y,]]:=true;
son[y,]:=;
size[y]:=size[son[y,]]+;
father[y]:=y+z;
if father[y]>n then father[y]:=n+;
end;
end;
end; begin
init;
main;
end.

bzoj 2002 LCT的更多相关文章

  1. BZOJ 2002 LCT板子题

    思路: LCT啊... (分块也行) 不过YOUSIKI出了一道“弹飞大爷” 就不能用分块水过去了 //By SiriusRen #include <cstdio> #include &l ...

  2. 以 BZOJ 2002 为例学习有根树LCT(Link-Cut Tree)

    以BZOJ 2002 弹飞绵羊为例学习有根树LCT(Link-Cut Tree) 注:本文非常简单,只涉及有根树LCT,对于无根树,LCT还有几个本文没有提到的操作,以后慢慢更新 =v= 知识储备 [ ...

  3. BZOJ 2002 && BZOJ 2409 LCT && BZOJ 3282 初步练习

    #include <cstdio> ; inline void Get_Int(int & x) { ; ') ch=getchar(); +ch-'; ch=getchar(); ...

  4. lct 模版题 bzoj 2002 2049

    很早就有人给我推荐的模版题,然后我最近才刷的(' '    ) 昨天的tree 不知道比他们高到哪里去了,我和他谈笑风生啊! bzoj 2002 弹飞绵羊 重点:这道题的cut和link 由于这道题链 ...

  5. bzoj 2002 Bounce 弹飞绵羊

    bzoj 2002 Bounce 弹飞绵羊 设一个虚拟节点表示被弹飞,则每个点的后继点是唯一确定的,每个点向它的后继点连边,就形成了一颗树. 询问就是问某个节点到虚拟节点的路径长度,修改就删除原来向后 ...

  6. [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree)

    [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree) 题面 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一 ...

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

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2002 [题意] 给定n个数的序列,i可以跳到i+k[i],需要能够修改k并可以查询跳出 ...

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

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

  9. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 lct 动态树 splay

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 http://blog.csdn.net/frods/article/details/5224 ...

随机推荐

  1. Index of my articles

    65:一个表格说明RelativeLayout中的几个重要属性[Written By KillerLegend] (2013-10-16 21:59) 64:win7修改软件[授权给…]后面的名称 ( ...

  2. PHP 把GBK编码转换为UTF8

    //把GBK编码转换为UTF8 $name="勿以善小而不为"; $name=iconv("GBK", "UTF-8", $name);

  3. SQL Server 基础:拾遗

    1.一条完整的sql语句: select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 having 筛选条件 ...

  4. wing IDE破解方法

    WingIDE是我接触到最好的一款Python编译器了.但其属于商业软件,注册需要一笔不小的费用.因此,这篇简短的文章主要介绍了破解WingIDE的方法.破解软件仅供学习或者教学使用,如果您是商业使用 ...

  5. STM32F0xx_看门狗(独立+窗口)配置详细过程

    Ⅰ.概述 对于看门狗,我觉得做单片机或者嵌入式开发的人员来说并不陌生,今天总结STM32F0看门狗的功能,F0的看门狗有两种:独立和窗口看门狗. 今天提供两种看门狗的软件工程实例,供大家下载. 两种看 ...

  6. python35

    在计算机内存中,统一使用Unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为UTF-8编码.Python对bytes类型的数据用带b前缀的单引号或双引号表示x = b'ABC' //每个字 ...

  7. 菜鸟学习Spring——60s利用JoinPoint获取参数的值和方法名称

    一.概述 AOP的实现方法在上两篇博客中已经用了两种方法来实现现在的问题来了虽然我们利用AOP,那么客户端如何信息传递?利用JoinPoint接口来实现客户端给具体实现类的传递参数. 二.代码演示. ...

  8. 算法系列7《CVN》

    计算CVN时使用二个64位的验证密钥,KeyA和KeyB. 1) 计算CVN 的数据源包括: 主账号(PAN).卡失效期和服务代码,从左至右顺序编排. 4123456789012345+8701+11 ...

  9. Percona-Xtrabackup 2.3.3 慢查询依旧堵塞MariaDB备份(三)

    MariaDB [yoon]> select version();+---------------------+| version() |+---------------------+| 10. ...

  10. iOS代码实践总结

    转载地址:http://mobile.51cto.com/hot-492236.htm 最近一个月除了专门抽时间和精力重构之外,还有就是遇到需要添加功能的模块的时候,由于项目中的代码历史因素比较多,第 ...