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 两种方法的更多相关文章

  1. bzoj 2002 HNOI 2010 弹飞绵羊

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

  2. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  3. BZOJ 2002:Bounce 弹飞绵羊(分块)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 14944  Solved: 7598 [Su ...

  4. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 ...

  5. bzoj 2002 : [Hnoi2010]Bounce 弹飞绵羊 (LCT)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 题面: 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: ...

  6. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 9071  Solved: 4652[Submi ...

  7. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 LCT

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...

  8. bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 4055  Solved: 2172[Submi ...

  9. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (动态树LCT)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2843  Solved: 1519[Submi ...

随机推荐

  1. codeforces 709B B. Checkpoints(水题)

    题目链接: B. Checkpoints 题意: 给了n个点,现在给一个起点,问最少访问n-1个点的最小行走距离是多少; 思路: 分情况讨论就好了; AC代码: #include <iostre ...

  2. 好玩的-记最近玩的几个经典ipad ios游戏

    最近回了趟家,在家里闲着没事去app store找了找一些高分游戏玩一玩,下面就是我最近玩的游戏. 海岛奇兵 想必大家都很了解,这是由开发过clash of clan部落冲突的公司所开发的另一款多人策 ...

  3. 2014 Super Training #1 C Ice-sugar Gourd 模拟,扫描线

    原题 HDU 3363 http://acm.hdu.edu.cn/showproblem.php?pid=3363 给你一个串,串中有H跟T两种字符,然后切任意刀,使得能把H跟T各自分为原来的一半. ...

  4. View (二) 自定义属性 自定义属性的格式详解

    自定义属性格式一共有十种: 1. reference:参考某一资源ID. 2. color:颜色值. 3. boolean:布尔值. 4. dimension:尺寸值. 5. float:浮点值. 6 ...

  5. 教你10分钟内在Windows上完成Rails开发环境的安装和配置

    原文:http://www.cnblogs.com/tambor/archive/2011/12/25/rails_anzhuang_railsinstaller.html 一般来说,Windows开 ...

  6. [转]Linux查看物理CPU个数、核数、逻辑CPU个数

    From : http://www.cnblogs.com/emanlee/p/3587571.html # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个 ...

  7. C语言 函数理解(以数组做参数)

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int run(int *p){ // ...

  8. PowerDesigner打开设计文件后提示failed to read the fileXXX的解决办法

    擦,一身盗汗.一向的设计信息都在设计图里!竟然坏了,坏了!!!!! 惊.怒.悲 固然可以经由过程数据库当前状况反向工程.然则那么注解.我写的提示这些器材都邑消散. 比来的备份是10天前,恢复也会有必然 ...

  9. Asp.net通过Jquery操作WebService进行Ajax读写

    一说到开始,我们当然需要项目. 首先,创建一个Asp.net Web 应用,然后新增一个名称为“Web 服务”的文件,也就是后缀名为".asmx"的文件,然后需要进行配置一下,在W ...

  10. listview的头布局把我的ACTION_DOWN事件给吃了.....

    因为头布局的viewpager自己处理点击事件 public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) ...