Bounce 弹飞绵羊

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002

分块

将整个大区间分成若干块,每个点维护到下一个块需要跳的次数以及会跳到哪个点(分块要注意细节,区间开闭容易弄乱)。

代码如下:

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define B (int(sqrt(n)))
#define N 200000
using namespace std;
struct nod{
int num;
int next,cost;
}a[N+];
int n,m;
int main(void){
scanf("%d",&n);
for(int i=;i<n;++i)
scanf("%d",&a[i].num);
for(int i=n-;i>=;--i){
int index=i+a[i].num;
int R=min(n,((i/B)+)*B);
if(index>=R){/**直接if(index/B>i/B)会出现始终不成立的情况导致后面陷入死循环**/
a[i].cost=;
a[i].next=index;
}else{
a[i].cost=a[index].cost+;
a[i].next=a[index].next;
}
}
scanf("%d",&m);
while(m--){
int type;
scanf("%d",&type);
if(type==){
int index,sum=;
scanf("%d",&index);
while(index<n){
sum+=a[index].cost;
index=a[index].next;
}
printf("%d\n",sum);
}else if(type==){
int index,num;
scanf("%d%d",&index,&num);
int block=index/B;
a[index].num=num;
for(int i=index;i>=block*B;--i){
int t=a[i].num+i;
int R=min(n,(block+)*B);
if(t>=R){
a[i].cost=;
a[i].next=t;
}else{
a[i].cost=a[t].cost+;
a[i].next=a[t].next;
}
}
}
}
}

Bounce 弹飞绵羊的更多相关文章

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

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

  2. 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 link-cut-tree

    2016-05-30 11:51:59 用一个next数组,记录点x的下一个点是哪个 查询时,moveroot(n+1),access(x),splay(x) ,输出size[ch[x][0]]即为答 ...

  3. 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 分块

    [bzoj2002][Hnoi2010]Bounce 弹飞绵羊 2014年7月30日8101 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀 ...

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

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

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

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

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

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

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

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

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

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

  9. 【BZOJ2002】 [Hnoi2010]Bounce 弹飞绵羊

    BZOJ2002 [Hnoi2010]Bounce 弹飞绵羊 Solution 很早以前写的一道分块题,最近在搞LCT,又做了一遍. 1.LCT做法 看到这种动态修改,想下LCT怎么维护. 修改操作就 ...

随机推荐

  1. 从Chrome源码看浏览器如何构建DOM树

    .aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto } p { font-size: 1 ...

  2. java类构造器的理解

    子类不能继承父类的构造器(构造方法或者构造函数),但是父类的构造器带有参数的,则必须在子类的构造器中显式地通过super关键字调用父类的构造器并配以适当的当属列表. 如果父类有无参构造器,则在子类的构 ...

  3. PHP关于foreach使用引用变量的坑

    写PHP好多年,但仍然会犯低级错误,今天遇到个 foreach中引用变量时的坑,PHP版本为 5.6.12 代码如下: <?php $arr = ['a', 'b', 'c', 'd', 'e' ...

  4. HDU1496 hash

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. Fedora24 升级到25

    1 安装dnf-plugin-system-upgrade dnf install dnf-plugin-system-upgrade 2 更新软件包 dnf system-upgrade downl ...

  6. angular-ui-bootstrap插件API - Pagination

    Pagination: 案例 <!DOCTYPE html> <html lang="en" ng-app="myApp"> <h ...

  7. COCOS2D-JS入门-官网template源码解析

    首先介绍几个概念: 导演: 导演 (Director)是Cocos2d-JS引擎抽象的一个对象,Director是整个Cocos2d-JS引擎的核心,是整个游戏的导航仪,游戏中的一些常用操作就是由Di ...

  8. iScroll 下 a 标签失效

    遇到个莫名其妙的问题,iScroll 下的 a 标签点击没有反应了,不管怎么调整 z-index 都无效果,很是无语. 查找半天后找到解决方法: $(function(){ new IScroll(' ...

  9. CodeForces 706D Vasiliy's Multiset

    字典树. 比较经典的题目了.把每一个数字都插入到字典树中,询问的时候如果$x$的第$i$位是$p$,那么尝试着在字典树上往$pXOR1$的节点走下去,没有$pXOR1$节点的话再走$p$的.删除操作的 ...

  10. 【JS】倒计时

    描述: 先要链接jquery.js,这样写法可以直接放JS文件运行. //放在图片里定位的倒计时 //顶图里面定位才使用的代码 document.writeln("<style> ...