【lct】bzoj2002 [Hnoi2010]Bounce 弹飞绵羊
lct板子,此题主要有cut操作和link操作。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 200005
#define INF 2147483647
int fa[maxn],val[maxn],c[maxn][2],root,tot,siz[maxn];
bool delta[maxn],is_root[maxn];
void Maintain(int x)
{
siz[x]=siz[c[x][0]]+siz[c[x][1]]+1;
}
//void Mark(int x){
// if(x){
// delta[x]^=1;
// }
//}
//void pushdown(int x){
// if(delta[x]){
// Mark(c[x][0]);
// Mark(c[x][1]);
// swap(c[x][0],c[x][1]);
// delta[x]=0;
// Maintain(x);
// }
//}
//void NewNode(int &x,int Fa)
//{
// x=++tot;
// fa[x]=Fa;
// c[x][0]=c[x][1]=0;
// siz[x]=1;
//}
void Rotate(int x,bool flag)
{
int y=fa[x];
// pushdown(y);
// pushdown(x);
c[y][!flag]=c[x][flag];
if(c[x][flag]){
fa[c[x][flag]]=y;
}
if(fa[y] && c[fa[y]][c[fa[y]][1]==y]==y){
c[fa[y]][c[fa[y]][1]==y]=x;
}
fa[x]=fa[y];
c[x][flag]=y;
fa[y]=x;
if(is_root[y]){
is_root[y]=0;
is_root[x]=1;
}
Maintain(y);
Maintain(x);
}
void Splay(int x)
{
if(!x || is_root[x]){
return;
}
// pushdown(x);
int y;
while(y=fa[x],(!is_root[x])){
if(is_root[y]){
Rotate(x,c[y][0]==x);
}
else{
if((c[y][0]==x)==(c[fa[y]][0]==y)){
Rotate(y,c[fa[y]][0]==y);
}
else{
Rotate(x,c[y][0]==x);
y=fa[x];
}
Rotate(x,c[y][0]==x);
}
}
Maintain(x);
}
void Access(int x){
int y;
Splay(x);
while(fa[x]){
y=fa[x];
Splay(y);
if(c[y][1]){
is_root[c[y][1]]=1;
}
is_root[x]=0;
c[y][1]=x;
Splay(x);
}
if(c[x][1]){
is_root[c[x][1]]=1;
c[x][1]=0;
}
}
int FindRoot(int x){
Access(x);
Splay(x);
while(c[x][0]){
x=c[x][0];
}
return x;
}
void cut(int x){
Access(x);
Splay(x);
fa[c[x][0]]=0;
if(c[x][0]){
is_root[c[x][0]]=1;
}
c[x][0]=0;
}
void link(int x,int y){
Access(x);
Splay(x);
// Mark(c[x][0]);
Access(y);
Splay(y);
c[y][1]=x;
fa[x]=y;
is_root[x]=0;
}
int calc(int x){
Access(x);
Splay(x);
return siz[c[x][0]]+1;
}
int n,m;
int main(){
// freopen("bzoj2002.in","r",stdin);
// freopen("bzoj2002.out","w",stdout);
int op,d,g;
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&d);
fa[i]=(i+d<=n ? i+d : 0);
c[i][0]=c[i][1]=0;
siz[i]=1;
delta[i]=0;
is_root[i]=1;
}
scanf("%d",&m);
for(int i=1;i<=m;++i){
scanf("%d%d",&op,&d); ++d;
if(op==1){
printf("%d\n",calc(d));
}
else{
scanf("%d",&g);
cut(d);
if(d+g<=n){
link(d,d+g);
}
}
}
return 0;
}
【lct】bzoj2002 [Hnoi2010]Bounce 弹飞绵羊的更多相关文章
- BZOJ2002 Hnoi2010 Bounce 弹飞绵羊 【LCT】【分块】
BZOJ2002 Hnoi2010 Bounce 弹飞绵羊 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始, ...
- [bzoj2002][Hnoi2010]Bounce弹飞绵羊_LCT
Bounce弹飞绵羊 bzoj-2002 Hnoi-2010 题目大意:n个格子,每一个格子有一个弹簧,第i个格子会将经过的绵羊往后弹k[i]个,达到i+k[i].如果i+k[i]不存在,就表示这只绵 ...
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 [分块][LCT]
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...
- [BZOJ2002] [Hnoi2010] Bounce 弹飞绵羊 (LCT)
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...
- BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊(LCT)
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在 他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装 ...
- [bzoj2002][Hnoi2010]Bounce弹飞绵羊——分块
Brief description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装 ...
- bzoj2002 [Hnoi2010]Bounce 弹飞绵羊【分块】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 这一题除了LCT解法,还有一种更巧妙,代码量更少的解法,就是分块.先想,如果仅仅记录每 ...
- bzoj2002 [Hnoi2010]Bounce 弹飞绵羊——分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 第一次用分块,感觉超方便啊: 如果记录每个点的弹力系数,那么是O(1)修改O(n)查询 ...
- 【分块】【LCT】bzoj2002 [Hnoi2010]Bounce 弹飞绵羊
分块,每个点统计还有几步弹出该块,以及它弹出块后的下一个节点是哪个点. 注意:update某个点的时候,会可能对当前块内 该点及以前的点 产生影响,所以对这部分点进行更新. #include<c ...
随机推荐
- python小爬虫练手
一个人无聊,写了个小爬虫爬取不可描述图片.... 代码太短,就暂时先往这里贴一下做备份吧. 注:这是很严肃的技术研究,当然爬下来的图片我会带着批判性的眼光审查一遍的.... :) #! /usr/ ...
- TinyOS 代码分析
1.Basestation案例 位于/opt/tinyos-main-master/apps/Basetation 1.1本例的顶层结构图: 1.2软件实现流程 1) uartIn,uartOut ...
- windows和linux修改python的pip源
python的pip安装包非常方便,然而其默认的镜像源在国外,下载的速度非常慢,推荐改成国内的镜像源. window平台修改pip源 找到系统盘下C:\C:\Users\用户名\AppData\Roa ...
- offset宏的讲解【转】
转自:http://blog.csdn.net/tigerjibo/article/details/8299584 1.offset宏讲解 #define offsetof(TYPE, MEMBER) ...
- Django 1.10文档中文版Part3
目录 2.7 第一个Django app,Part 5:测试 2.7.1 自动化测试介绍 2.7.2 基本的测试策略 2.7.3 编写我们的第一个测试程序 2.7.4 测试一个视图 2.7.5 测试越 ...
- 访问公网WebService服务
接下来,我们演示如何访问公网webservice服务. 我们以访问 http://www.webxml.com.cn/zh_cn/index.aspx 为例,主要演示手机号码归属地查询服务(使用说明书 ...
- Linux下进程信息/proc/pid/status的深入分析
https://blog.csdn.net/beckdon/article/details/48491909
- MINIBASE源代码阅读笔记之HFPage
HFPage heap file的page的类 成员 slot_t:用来表示页里的slot,包括offset和length slot[]:倒着生长的slot array slotCnt:有多少已用sl ...
- [BZOJ4945][Noi2017]游戏 2-sat
对于所有的x,我们枚举他的地图类型,事实上我们只需要枚举前两种地形就可以覆盖所有的情况. 之后就变成了裸的2-sat问题. 对于一个限制,我们分类讨论: 1.h[u]不可选,跳过 2.h[v]不可选, ...
- C# 6.0 新特性 (四)
原文: 1.http://www.cnblogs.com/BoyceYang/p/3711343.html 2.http://www.cnblogs.com/lhking/p/3660182.html ...