LCT access完了一定splay再用!!!

悲伤= =

LCT裸题 把调出去设虚点n+1即可

//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200010
#define ls(x) t[x].son[0]
#define rs(x) t[x].son[1]
#define fa(x) t[x].fa
#define nroot(x) (ls(fa(x))==x||rs(fa(x))==x)
using namespace std; struct node
{
int sz,fa,son[2]; bool rev;
}t[N]; void pushup(int x)
{
t[x].sz = t[ls(x)].sz + t[rs(x)].sz + 1;
} void rotate(int x)
{
if(!x||!nroot(x)) return;
int f = fa(x),gf = fa(f);
int k = (rs(f) == x), p = k^1;
if(nroot(f)) t[gf].son[rs(gf)==f] = x;
t[x].fa = gf; t[f].fa = x;
if(t[x].son[p]) t[t[x].son[p]].fa = f;
t[f].son[k] = t[x].son[p];
t[x].son[p] = f;
pushup(f); pushup(x);
} void pushdown(int x)
{
if(!x || !t[x].rev) return;
swap(ls(x),rs(x));
if(ls(x)) t[ls(x)].rev^=1;
if(rs(x)) t[rs(x)].rev^=1;
t[x].rev^=1;
} void push(int x)
{
if(nroot(x)) push(fa(x));
pushdown(x);
} void splay(int x)
{
push(x);
while(nroot(x))
{
int f = fa(x), gf = fa(f);
if(nroot(gf))
(rs(f)==x)^(rs(gf)==f)?rotate(x):rotate(f);
rotate(x);
}
pushup(x);
} void access(int x)
{
int y = 0;
do
{
//printf("%d\n",x);
splay(x);
t[x].son[1] = y;
pushup(x);
y = x; x = t[x].fa;
}while(x);
} void makeroot(int x)
{
access(x); splay(x); t[x].rev=1;// pushdown(x);
} void link(int x,int y)
{
makeroot(x); t[x].fa = y;
} void cut(int x,int y)
{
makeroot(y); access(x); splay(x);
//printf("%d %d\n",t[y].sz,rs(y));
if(t[x].sz == 2 && ls(x) == y)
t[x].son[0] = 0, t[y].fa = 0,pushup(x);
}
int k[N];
int main()
{
int n,x,y,opt,m;
scanf("%d",&n);
for(int i=1;i<=n+1;i++) t[i].sz=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&k[i]);
if(i+k[i]>n) link(i,n+1);
else link(i,i+k[i]);
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&opt,&x);
//for(int j=1;j<=n+1;j++)
// printf("%d ",t[j].fa);
//printf("\n");
x++;
if(opt==1)
{
makeroot(n+1);
//printf("MMP\n");
//for(int j=1;j<=n+1;j++)
// printf("%d ",t[j].fa);
access(x); splay(x);
//printf("%d %d\n",ls(5),rs(5));
printf("%d\n",t[x].sz-1);
}
else
{
scanf("%d",&y);
cut(x,x+k[x]>n?n+1:x+k[x]);
k[x] = y;
link(x,x+k[x]>n?n+1:x+k[x]);
}
}
return 0;
}

BZOJ2002 [HNOI2010] 弹飞绵羊的更多相关文章

  1. BZOJ2002[Hnoi2010]弹飞绵羊——LCT

    题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...

  2. 【BZOJ2002】弹飞绵羊(Link-Cut Tree)

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

  3. P3203 [HNOI2010]弹飞绵羊(LCT)

    P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...

  4. [HNOI2010] 弹飞绵羊 (分块)

    [HNOI2010] 弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上 ...

  5. 洛谷 P3203 [HNOI2010]弹飞绵羊 解题报告

    P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...

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

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

  7. 「洛谷P3202」[HNOI2010]弹飞绵羊 解题报告

    P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...

  8. [Luogu P3203] [HNOI2010]弹飞绵羊 (LCT维护链的长度)

    题面 传送门:洛谷 Solution 这题其实是有类似模型的. 我们先考虑不修改怎么写.考虑这样做:每个点向它跳到的点连一条边,最后肯定会连成一颗以n+1为根的树(我们拿n+1代表被弹出去了).题目所 ...

  9. 【codevs2333】&【BZOJ2002】弹飞绵羊[HNOI2010](分块)

    我其实是在codevs上看到它的题号后才去做这道题的...2333... 题目传送门:codevs:http://codevs.cn/problem/2333/ bzoj:http://www.lyd ...

随机推荐

  1. 史上最全最实用HBuilder快捷键大全

    史上最全最实用HBuilder快捷键大全 一.文件操作二.编辑操作三.插入操作四.转义操作五.选择操作六.跳转操作七.查找操作八.运行九.视图一.文件操作新建菜单: ctrl + N新建: ctrl ...

  2. NOIp 数据结构专题总结 (1):STL、堆、并查集、ST表、Hash表

    系列索引: NOIp 数据结构专题总结 (1) NOIp 数据结构专题总结 (2) STL structure STL 在 OI 中的运用:https://oi.men.ci/stl-in-oi/ s ...

  3. 夯实Java基础系列7:Java 代码块和执行顺序

    本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial 喜欢的话麻烦点下 ...

  4. CentOS-7.4(1708)release notes发行注记

    Red Hat Enterprise Linux 当前的最新版本是 7.3. Red Hat Enterprise Linux 7 当前仅支持 64 位CPU:64-bit AMD.64-bit In ...

  5. content is not supported outside 'script" or asp content' region

    https://stackoverflow.com/questions/48915080/asp-net-content-is-not-supported-outside-the-script-or- ...

  6. P2239螺旋矩阵

    传送 看到这数据范围,显然咱不能暴力直接模拟(二维数组开不下,而且会T掉) 我们目前有两种选择: 1.优化暴力  走这边(jyy tql%%%) 2.数学做法 我们看一下题目中的那个矩阵 我们能不能找 ...

  7. C#连redis

    引入 Microsoft.Extensions.Caching.Redis其实就是封装了StackExchange.redis 控制台例子: class Program { public static ...

  8. mysql 开放远程连接权限连不上

    1.my.cof配置了:bind-address=addr  或   skip-networking,需要注释 2.防火墙限制3306端口: iptables -L -n --line-numbers ...

  9. 学习HTML5 全局属性 accesskey-title

    属性classcontextmenu指定一个元素的上下文菜单.当用户右击该元素,出现上下文菜单dirdropzone指定是否将数据复制,移动,或链接,或删除idspellcheck检测元素是否拼写错误 ...

  10. [LeetCode] 287. Find the Duplicate Number(Floyd判圈算法)

    传送门 Description Given an array nums containing n + 1 integers where each integer is between 1 and n  ...