【BZOJ 2002】【Hnoi 2010】弹飞绵羊 分块||Link Cut Tree 两种方法
ShallWe,Yveh,hmy,DaD3zZ,四人吃冰糕从SLYZ超市出来后在马路上一字排开,,,吃完后发现冰糕棍上写着:“向狮子座表白:愿做你的小绵羊”,,,
好吧在这道题里我们要弹飞绵羊,有分块和lct两种方法。
分块:
#include<cmath>
#include<cstdio>
#define for1(i,a,n) for(int i=(a);i<=(n);i++)
#define for3(i,a,n) for(int i=(a);i>=(n);i--)
#define read(x) x=getint()
using namespace std;
inline int getint(){char c;int ret=0;for(c=getchar();c<'0'||c>'9';c=getchar());for(;c>='0'&&c<='9';c=getchar())ret=ret*10+c-'0';return ret;}
const int N=200003;
int n,o[N],t[N],w[N],step[N];
inline void work(int i){
int j=i+t[i];
if (j>n) w[i]=n+1,step[i]=1;
if (o[i]==o[j]){
w[i]=w[j];
step[i]=step[j]+1;
}else{
w[i]=j;
step[i]=1;
}
}
int main(){
read(n);
for1(i,1,n) read(t[i]);
int pn=floor(sqrt(n)),q,id,x,y;
for1(i,1,n) o[i]=(i-1)/pn+1;
for3(i,n,1) work(i);
read(q);
while (q--){
read(id);
if (id==1){
read(x); x++; y=0;
while (x<=n){
y+=step[x];
x=w[x];
}
printf("%d\n",y);
}else{
read(x); read(y); x++;
t[x]=y;
for3(i,x,1)
if (o[x]==o[i]) work(i);
else break;
}
}
return 0;
}
LCT(为什么我的lct的常数辣么大T_T)
#include<cstdio>
#include<algorithm>
#define for1(i,a,n) for(int i=(a);i<=(n);i++)
#define read(x) x=getint()
using namespace std;
inline int getint(){char c;int ret=0;for(c=getchar();c<'0'||c>'9';c=getchar());for(;c>='0'&&c<='9';c=getchar())ret=ret*10+c-'0';return ret;}
const int N=200003;
struct node *null;
struct node{
node();
node *fa,*ch[2];
int s;
void count() {s=1+ch[0]->s+ch[1]->s;}
bool pl() {return fa->ch[1]==this;}
void setc(node *r,bool c) {ch[c]=r; r->fa=this;}
bool check() {return fa==null||((fa->ch[0]!=this)&&(fa->ch[1]!=this));}
}*rt[N];
node::node(){s=1;fa=ch[0]=ch[1]=null;}
int n;
inline void Build(){null=new node;null->s=0;null->ch[0]=null->ch[1]=null->fa=null;}
inline void rotate(node *r){
node *f=r->fa; bool c=r->pl();
if (f->check()) r->fa=f->fa;
else f->fa->setc(r,f->pl());
f->setc(r->ch[c^1],c);
r->setc(f,c^1);
f->count(); r->count();
}
inline void splay(node *r){
for(;!r->check();rotate(r))
if (!r->fa->check()) rotate(r->fa->pl()==r->pl()?r->fa:r);
r->count();
}
inline void access(node *r){
for(node *c=null;r!=null;r=r->fa){
splay(r);
r->setc(c,1);
r->count();
c=r;
}
}
inline void link(node *r,node *f){
access(r); splay(r);
r->ch[0]->fa=null; r->ch[0]=null; r->fa=f; r->count();
}
int main(){
Build();
int t,q,x,y;
read(n);
for1(i,1,n) rt[i]=new node;
for1(i,1,n) {read(t); if (i+t<=n) rt[i]->fa=rt[i+t];}
read(q);
while (q--){
read(x);
if (x==1){
read(y); y++;
access(rt[y]); splay(rt[y]); printf("%d\n",rt[y]->s);
}else{
read(x); read(y); x++;
if (x+y<=n) link(rt[x],rt[x+y]);
else link(rt[x],null);
}
}
return 0;
}
BeiYu的常数总是比我的要小,,本蒟蒻还得继续努力啊
【BZOJ 2002】【Hnoi 2010】弹飞绵羊 分块||Link Cut Tree 两种方法的更多相关文章
- bzoj 2002 HNOI 2010 弹飞绵羊
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- BZOJ 2002:Bounce 弹飞绵羊(分块)
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 14944 Solved: 7598 [Su ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 ...
- bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 9071 Solved: 4652[Submi ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 LCT
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 4055 Solved: 2172[Submi ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (动态树LCT)
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2843 Solved: 1519[Submi ...
随机推荐
- 【jQuery Demo】jQuery打造动态下滑菜单
作者:漫凯维奇 来源:[教程]jQuery打造动态下滑菜单 Tip:这只是一个转载,源代码可以在上面的来源博文中下载 此教程将分步讲解如何使用JQuery和CSS打造一个炫酷动感菜单.效果如 ...
- 拓扑排序 codevs 4040 cojs 438
codevs 4040 EZ系列之奖金 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 由于无敌的WRN在2015年世界英 ...
- 《EXO指数型组织》阅读脑图
书籍:<EXO指数型组织:打造独角兽公司的11个最强属性> 预览链接:https://www.processon.com/view/link/57ce8279e4b08cbf6ca8f85 ...
- HDU 2487 Ugly Windows
递归求解,代码不太好看,是2013年7月写的 代码: #include<stdio.h> #include<iostream> #include<string.h> ...
- HTML5-WebSocket技术学习(1)
WebSocket是为解决客户端与服务端实时通信而产生的技术. 介绍它是什么的废话不多说了,直接说怎么用: 客户端: 1.创建一个 EventSource 对象 var es = new EventS ...
- 18种CSS3loading效果完整版,兼容各大主流浏览器,提供在线小工具使用
今天把之前分享的两篇博客<CSS3实现10种Loading效果>和 <CSS3实现8种Loading效果[二]>整理了一下.因为之前所分享的各种loading效果都只是做了we ...
- Linux下Tomcat的启动、关闭、杀死进程
打开终端 cd /java/tomcat #执行 bin/startup.sh #启动tomcat bin/shutdown.sh #停止tomcat tail -f logs/catalina.ou ...
- MySQL主从同步几个文件
MySQL主从同步: M锁表 M导出S导入 M解锁 M建同步帐号 S获取点位:产生master.info S开启同步 3306: mysql-bin.0000x mysql-bin.index ...
- Linux Linux程序练习十(网络编程大文件发送)
//网络编程客户端--大文件传输 #include <stdio.h> #include <stdlib.h> #include <string.h> #inclu ...
- C语言 数组做函数参数退化为指针的技术推演
//数组做函数参数退化为指针的技术推演 #include<stdio.h> #include<stdlib.h> #include<string.h> //一维数组 ...