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. [Bzoj]1012最大数maxnumber

    题目如上(线段树???),蒟蒻第二眼想法(其实这道题正解是单队的说,但蒟蒻刚学线段树,于是...就) 献上黑历史: RE是因为蒟蒻数组开太小:第一次开110000:第二次开200000:结果就………… ...

  2. 安装hadoop-eclipse-plugin插件报错解决办法

    安装myecplise的hadoop-eclipse-plugin-2.2.0插件的时候,  把插件放到这个文件夹里 打开myeclipse windows-->preferences 点击 H ...

  3. C# 3.0相比C# 2.0增加的功能

    1.自动属性 (1)自动属性(Auto-Implemented Properties),C#自动属性可以避免原来我们手工的来声明一个私有成员变量以及和属性get,set的书写. public clas ...

  4. linux下使用autoconf制作Makefile

    第一步:常用工具安装:正所谓:"工欲善其事,必先利其器".我们常用的工具主要有GNU AutomakeGNU AutoconfGNU m4GNU Libtool1.查看自己系统中是 ...

  5. moodle其他代码

    , $sectionnum=false, $strictness=IGNORE_MISSING):给课程模块一个id,找出coursemoudle的描述 get_coursemodule_from_i ...

  6. TODO:字节序的一些理解

    TODO:字节序的一些理解 本文是小编对字节序的片面理解,希望对你有帮助哈. 字节序,即字节在电脑中存放时的序列与输入(输出)时的序列是先到的在前还是后到的在前. 1.Little endian:将低 ...

  7. 敏捷开发(十)- Scrum每日例会

    本文主要是为了检测你对SCRUM 评估会议的了解和使用程度, 通过本文你可以检测一下     1.你们的SCRUM 没人例会的过程和步骤    2.SCRUM 每日例会的输出结果一.会议目的      ...

  8. hdu1031

    #include <cstdio> #include <cstdlib> struct element{ int id; double sa; }e[10000]; int c ...

  9. 使用 Git 报错 error: src refspec master matches more than one.

    今天在使用 Git push 代码时遇到一个报错: error: src refspec master matches more than one. error: failed to push som ...

  10. Ubuntu 12.04 修改键盘映射

    背景: (1) 我的笔记本G450上,Page_up/Page_down键分别和Home/End在同一个键位上,需要同时按住Fn键才能敲出Home/End (2) 习惯用Vim的同志都有这个感觉,Es ...