BZOJ2002 [HNOI2010] 弹飞绵羊
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] 弹飞绵羊的更多相关文章
- BZOJ2002[Hnoi2010]弹飞绵羊——LCT
题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...
- 【BZOJ2002】弹飞绵羊(Link-Cut Tree)
[BZOJ2002]弹飞绵羊(Link-Cut Tree) 题面 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lost ...
- P3203 [HNOI2010]弹飞绵羊(LCT)
P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...
- [HNOI2010] 弹飞绵羊 (分块)
[HNOI2010] 弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上 ...
- 洛谷 P3203 [HNOI2010]弹飞绵羊 解题报告
P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...
- [BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree)
[BZOJ 2002] [HNOI2010]弹飞绵羊(Link Cut Tree) 题面 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一 ...
- 「洛谷P3202」[HNOI2010]弹飞绵羊 解题报告
P3203 [HNOI2010]弹飞绵羊 题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一 ...
- [Luogu P3203] [HNOI2010]弹飞绵羊 (LCT维护链的长度)
题面 传送门:洛谷 Solution 这题其实是有类似模型的. 我们先考虑不修改怎么写.考虑这样做:每个点向它跳到的点连一条边,最后肯定会连成一颗以n+1为根的树(我们拿n+1代表被弹出去了).题目所 ...
- 【codevs2333】&【BZOJ2002】弹飞绵羊[HNOI2010](分块)
我其实是在codevs上看到它的题号后才去做这道题的...2333... 题目传送门:codevs:http://codevs.cn/problem/2333/ bzoj:http://www.lyd ...
随机推荐
- django正常运行确报错的解决方法
django正常运行却报错的处理方法 出处 : https://www.infvie.com/ops-notes/django-normal-operation-error 报错一:self._soc ...
- Fractal
Fractal 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specifically, th ...
- [CSP-S模拟测试]:天才绅士少女助手克里斯蒂娜(数学+树状数组)
题目描述 红莉栖想要弄清楚楼下天王寺大叔的显像管电视对“电话微波炉(暂定)”的影响. 选取显像管的任意一个平面,一开始平面内有个$n$电子,初始速度分别为$v_i$,定义飘升系数为$$\sum \li ...
- java文件转码
完整项目带lib 参考 http://toyota2006.iteye.com/blog/540316 判断编码 package change; import info.monitorenter.cp ...
- Sublime Text3 代码编辑器使用笔记
Sublime Text3 作为一款代码的文本编辑器,有许多插件,这一点是我认为 Sublime Text3 很强大的原因之一.插件的安装可以参考下面的文章. Sublime Text3 插件安装教程 ...
- LintCode之合并排序数组II
题目描述: 分析:题目的意思是把数组A和数组B合并到数组A中,且数组A有足够的空间容纳A和B的元素,合并后的数组依然是有序的. 我的代码: public class Solution { /* * @ ...
- http请求方法,get 对比 post
本文转自:http://www.w3school.com.cn/tags/html_ref_httpmethods.asp 两种最常用的 HTTP 方法是:GET 和 POST. 什么是 HTTP? ...
- pve之daemon
pmxcfs The Proxmox Cluster file system (“pmxcfs”) is a database-driven file system for storing confi ...
- hdu6575Budget
Problem Description Avin’s company has many ongoing projects with different budgets. His company rec ...
- jQuery DataTables 分页
HTML:================================================================== <div class="ibox-con ...