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. properties + IO 读取配置文件

    1.项目目录树 2.配置文件config.properties username = sushe password = sushe url = jdbc:mysql://172.16.100.10:3 ...

  2. Perception(0-1.1)

    The perception modules run in the context of the process Cognition. They detect features in the imag ...

  3. For循环输出一个表格

    <!-- 作者:郑伟钊 时间:2017-01-16 描述:通过一个循环的嵌套输出一个表格 --> <?php header("Content-type:text/html; ...

  4. 【UOJ #280】【UTR #2】题目难度提升

    http://uoj.ac/problem/280 非常难想的贪心,用set\(O(nlogn)\). 调了一天qwq. 题解 #include<set> #include<cstd ...

  5. Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if expl

    检查你的用户名和密码是否正确 ,以及位置是否正确:

  6. 关于C#继承运用的总结

    整体代码部分: 解决方案: 父类Person类: using System; using System.Collections.Generic; using System.Linq; using Sy ...

  7. Zeppelin 用jdbc连接hive报错

    日志: Could not establish connection to jdbc:hive2://192.168.0.51:10000: Required field 'serverProtoco ...

  8. 3.使用secureCRT连接PC,LINUX,开发板

    1.设置secureCRT(可选项):http://www.linuxyw.com/linux/gongxiang/20130505/161.html 2.使用secureCRT远程登录linux 3 ...

  9. 去掉UItableview section headerview黏性

    UITabelView在style为plain时,在上拉是section始终粘在最顶上而不是跟随滚动而消失或者出现 可以通过设置UIEdgeInsetsMake: - (void)scrollView ...

  10. Python学习笔记——基础篇【第二周】——解释器、字符串、列表、字典、主文件判断、对象

    目录 1.Python介绍 2.Python编码 3.接受执行传参 4.基本数据类型常用方法 5.Python主文件判断 6.一切事物都是对象 7.   int内部功能介绍 8.float和long内 ...