B2002 [Hnoi2010]Bounce 弹飞绵羊 分块
原来做过,看大家都做这道题都热情高涨,沈爷爷debug这道题4天,作为告诉他这个题的人,我还有点不好意思。。。我自己也就做了一个小时。
其实这个题思路还好,就是维护每个点的出块次数和跳出块的位置,然后访问的时候直接调用块。
这个题还有一个比较坑的地方,就是每个绵羊只有到队尾的时候才会被弹飞,所以不用担心在中间停止的情况。
题干:
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系数ki,当绵羊达到第i个装置时,它会往后弹ki步,达到第i+ki个装置,若不存在第i+ki个装置,则绵羊被弹飞。绵羊想知道当它从第i个装置起步时,被弹几次后会被弹飞。为了使得游戏更有趣,Lostmonkey可以修改某个弹力装置的弹力系数,任何时候弹力系数均为正整数。
Input 第一行包含一个整数n,表示地上有n个装置,装置的编号从0到n-,接下来一行有n个正整数,依次为那n个装置的初始弹力系数。第三行有一个正整数m,接下来m行每行至少有两个数i、j,若i=,你要输出从j出发被弹几次后被弹飞,若i=2则还会再输入一个正整数k,表示第j个弹力装置的系数被修改成k。对于20%的数据n,m<=,对于100%的数据n<=,m<=
Output
对于每个i=1的情况,你都要输出一个需要的步数,占一行。
Sample Input Sample Output HINT
Source
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
struct node
{
int l,r;
}a[];
int outt[], times[];
int n,x,blo,bl[],top = ;
int f[],num = ;
void init(int x,int y)
{
lv(i,y,x)
{
// cout<<i<<" "<<f[i]<<endl;
if(i + f[i] > a[bl[i]].r)
{
times[i] = ;
outt[i] = i + f[i];
}
else
{
times[i] = + times[i + f[i]];
outt[i] = outt[i + f[i]];
}
}
}
int main()
{
read(n);
blo = sqrt(n);
duke(i,,n)
{
read(f[i]);
}
for(int i = ;i <= n;i += blo)
{
a[++num].l = i;
a[num].r = i + blo - ;
}
top = ;
duke(i,,n)
{
if(a[top].r < i)
{
top++;
}
bl[i] = top;
}
init(,n);
/*duke(i,1,n)
{
printf("%d ",outt[i]);
}
cout<<endl;
duke(i,1,n)
{
printf("%d ",times[i]);
}
cout<<endl;*/
int m;
/*duke(i,1,n)
{
printf("%d ",bl[i]);
}
cout<<endl;*/
read(m);
while(m--)
{
int x,y,z;
read(x);
read(y);
y += ;
if(x == )
{
int ans = times[y],z = outt[y];
//cout<<ans<<" "<<bl[y]<<" "<<z<<"="<<endl;
for(int i = bl[y];i <= num && z <= n;i++)
{
// cout<<ans<<" "<<z<<endl;
// cout<<z<<" "<<outt[z]<<endl;
ans += times[z];
z = outt[z];
}
printf("%d\n",ans);
}
else
{
read(z);
f[y] = z;
init(a[bl[y]].l,a[bl[y]].r);
}
}
return ;
}
B2002 [Hnoi2010]Bounce 弹飞绵羊 分块的更多相关文章
- 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 分块
[bzoj2002][Hnoi2010]Bounce 弹飞绵羊 2014年7月30日8101 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀 ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- 【BZOJ2002】 [Hnoi2010]Bounce 弹飞绵羊 分块/LCT
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在 他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装 ...
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 [分块][LCT]
Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...
- [bzoj2002][Hnoi2010]Bounce弹飞绵羊——分块
Brief description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装 ...
- bzoj2002 [Hnoi2010]Bounce 弹飞绵羊——分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2002 第一次用分块,感觉超方便啊: 如果记录每个点的弹力系数,那么是O(1)修改O(n)查询 ...
- COGS.1689.[HNOI2010]Bounce 弹飞绵羊(分块)
题目链接 /* 分块,维护从某位置跳到下一个块需要多少步 */ #include<cmath> #include<cstdio> #include<cctype> ...
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 分块
这个题体现了分块不只是最大值最小值众数次数,而是一种清真的思想. 我们把整个序列分块,在每个块里处理每个位置跳出这个块的次数和跳出的位置,那么每次修改n0.5,每次查询也是,那么O(m* n0.5)的 ...
- BZOJ2002 Hnoi2010 Bounce 弹飞绵羊 【LCT】【分块】
BZOJ2002 Hnoi2010 Bounce 弹飞绵羊 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始, ...
随机推荐
- Monkey测试总结
Monkey测试总结 1.什么是Monkey Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等), 实 ...
- Ajax——php基础知识(二)
header header('content-type:text/html; charset= utf-8');//设置编码格式为:utf-8 header('location:http://www. ...
- 【译】x86程序员手册04 - 2.2数据类型
2.2 Data Types 数据类型 Bytes, words, and doublewords are the fundamental data types (refer to Figure 2- ...
- [文章转载]-Java后端,应该日常翻看的中文技术网站 -江南白衣
Java后端,应该日常翻看的中文技术网站 1.内容生产者 InfoQ 中文技术第一站,佩服霍老板,真金白银地为中国程序员们生产内容. ImportNew 专门面向Java的内容生产者兼聚合者,偶然也有 ...
- 【sqli-labs】 less45 POST -Error based -String -Stacked Blind(POST型基于盲注的堆叠字符型注入)
和Less44一个名字 测试一下,发现是')闭合的 login_user=&login_password=1') or sleep(0.1)# 那就是没有错误显示的less42 login_u ...
- windows环境安装python虚拟环境
虚拟环境安装参考 https://www.cnblogs.com/suke99/p/5355894.html workon环境变量配置参照 https://www.cnblogs.com/jiuyan ...
- Android获取SD卡路径/内存的几种方法
Android获取SD卡路径 本篇将会带领大家学习如何获取android路径的几种常见用法,但在我开始bb之前需要大家清楚android中内存和外存之间的区别,下面进行简短介绍:android中的内存 ...
- Python 不定长参数、全局变量、局部变量 day4
一.不定长参数 在函数定义中,经常会碰到*args 和**kwargs作为参数. 事实上在函数中,*和**才是必要的,args和kwargs可以用其他名称代替 *args 是指不定数量的非键值对参数. ...
- pig常用命令
一.pig: pig提供了一个基于Hadoop的并行地执行数据流处理的引擎.它包含了一种脚本语言,称为Pig Latin.(类似SQL) 二.Pig Latin: 1.注释: 单行:-- 多行:/* ...
- colgroup 整行变色
<table border="2" width="100%"> <colgroup span="2" align=&quo ...