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. js dom 操作

    JS的DOM操作   1DOM是文档对象模型,这种模型为树模型:文档是指标签文档,对象是指文档中每个元素:模型是指抽象化的东西. 2间隔与延迟间隔执行一段代码(函数):window.setInterv ...

  2. Silverlight - GPU加速

    1. 在Silverlight plug-in上设置 <param name="enableGPUAcceleration" value="true" / ...

  3. caused by android.system.errnoexception open failed eacces (permission denied)解决方案,安卓6.0(API23)权限问题

    在API23+以上,不止要在AndroidManifest.xml里面添加权限 <uses-permission android:name="android.permission.RE ...

  4. How to using x++ code create GL journal[AX2012]

    static void FAN_GLImport(Args _args) { AxLedgerJournalTable header = new AxLedgerJournalTable(); AxL ...

  5. Oracle 10g 之自动收集统计信息

    从10g开始,Oracle在建库后就默认创建了一个名为GATHER_STATS_JOB的定时任务,用于自动收集CBO的统计信息.这个自动任务默认情况下在工作日晚上10:00-6:00和周末全天开启. ...

  6. 第十七章 调试及安全性(In .net4.5) 之 程序诊断

    1. 概述 生产环境中的程序,也是不能保证没有问题的.为了能方便的找出问题,.net提供了一些特性来进行程序诊断. 这些特性包括:logging.tracing .程序性能分析(profiling) ...

  7. LC.exe exited with code -1

    昨天从win8.1升级到win10之后, 一切还算顺利, 就是升级时间比较长. 但是快下班的时候 遇到一个问题, 是之前在win8.1上没遇到的, 首先代码win8.1 vs2013 上跑的时候一切正 ...

  8. C高级 服务器内核分析和构建 (一)

    引言 最经看cloud wind 的 skynet服务器设计. 觉得特别精妙. 想来个专题先剖析其通信层服务器内核 的设计原理. 最后再优化.本文是这个小专题的第一部分, 重点会讲解对于不同平台通信基 ...

  9. XSS的原理分析与解剖[转http://www.freebuf.com/articles/web/40520.html]

    0×01 前言: <xss攻击手法>一开始在互联网上资料并不多(都是现成的代码,没有从基础的开始),直到刺的<白帽子讲WEB安全>和cn4rry的<XSS跨站脚本攻击剖析 ...

  10. Mysql允许外网接入

    首先你可以为mysql创建一个账户,或者为root用户接入数据库. 授权用户指定所有主机以指定用户连接服务器 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDE ...