_bzoj2002 [Hnoi2010]Bounce 弹飞绵羊【分块】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2002
见一周目记录:http://www.cnblogs.com/ciao-sora/p/6099077.html
#include <cstdio>
#include <cmath> const int maxn = 200005; int n, m, a[maxn], to[maxn], need[maxn], siz, id, t1, t2, t3, haji; inline int qry(int pos) {
int rt = 0;
while (~pos) {
rt += need[pos];
pos = to[pos];
}
return rt;
}
inline void upd(int pos, int val) {
id = pos / siz;
haji = id * siz;
a[pos] = val;
for (int i = pos; i >= haji; --i) {
if (i + a[i] >= n) {
to[i] = -1;
need[i] = 1;
}
else if (i + a[i] >= (id + 1) * siz) {
to[i] = i + a[i];
need[i] = 1;
}
else {
to[i] = to[i + a[i]];
need[i] = need[i + a[i]] + 1;
}
}
} int main(void) {
scanf("%d", &n);
siz = (int)sqrt((float)n + 0.5f);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
for (int i = n - 1; ~i; --i) {
id = i / siz;
if (i + a[i] >= n) {
to[i] = -1;
need[i] = 1;
}
else if (i + a[i] >= (id + 1) * siz) {
to[i] = i + a[i];
need[i] = 1;
}
else {
to[i] = to[i + a[i]];
need[i] = need[i + a[i]] + 1;
}
}
scanf("%d", &m);
while (m--) {
scanf("%d%d", &t1, &t2);
if (t1 == 1) {
printf("%d\n", qry(t2));
}
else {
scanf("%d", &t3);
upd(t2, t3);
}
}
return 0;
}
_bzoj2002 [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)查询 ...
- B2002 [Hnoi2010]Bounce 弹飞绵羊 分块
原来做过,看大家都做这道题都热情高涨,沈爷爷debug这道题4天,作为告诉他这个题的人,我还有点不好意思...我自己也就做了一个小时. 其实这个题思路还好,就是维护每个点的出块次数和跳出块的位置,然后 ...
- COGS.1689.[HNOI2010]Bounce 弹飞绵羊(分块)
题目链接 /* 分块,维护从某位置跳到下一个块需要多少步 */ #include<cmath> #include<cstdio> #include<cctype> ...
- bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 分块
这个题体现了分块不只是最大值最小值众数次数,而是一种清真的思想. 我们把整个序列分块,在每个块里处理每个位置跳出这个块的次数和跳出的位置,那么每次修改n0.5,每次查询也是,那么O(m* n0.5)的 ...
随机推荐
- CentOS 6.x DRBD
CentOS 6.x DRBD 一.drbd概述 Distributed Replicated Block Device(DRBD)是一种基于软件的,无共享,复制的存储解决方案,在服务器之间的 ...
- Oracle 数据库管理员的任务
设计.实施和维护 Oracle 数据库时,按优先次序排列的任务包括: 1. 确定数据库服务器硬件 2. 安装 Oracle 软件 3. 为数据库和安全策略制定计划 4. 创建.移植和打 ...
- Hadoop-异常-Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/avro/io/DatumReader
//maven org.apache.avr 下载不完全 ,去maven If you are using maven to build your jar, you need to add the ...
- 设计模式之解释器模式(Interpreter)摘录
23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程,它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...
- sdut 面向对象程序设计上机练习四(变量引用)
面向对象程序设计上机练习四(变量引用) Time Limit: 1000MS Memory limit: 65536K 题目描写叙述 将变量的引用作为函数形參,实现2个int型数据交换. 输入 输入2 ...
- HDU 1031.Design T-Shirt【结构体二次排序】【8月21】
Design T-Shirt Problem Description Soon after he decided to design a T-shirt for our Algorithm Board ...
- Spring AOP监控SQL运行
对数据库连接池Proxool比較熟悉的读者,都知道Proxool能够记录SQL运行内容和时间等信息日志. 我们能够将该日志记录专门的SQL日志文件.对于查找运行特别耗时的SQL起了不小的作用. 对于一 ...
- web.xml中的ServletContextListener
要想了解ServletContextListener,先看看web.xml中的<listener>配置. 一)web.xml中的内容载入顺序: 首先能够肯定的是,载入顺序与它们在 web. ...
- [办公自动化]chrome浏览器的书签在哪里存放
最近换电脑了. 硬盘直接挂在了新电脑上.忘记导出Chrome的浏览器的书签了. 对于书签,Windows XP和Windows 7的路径都是: C:\Documents and Settings\** ...
- TCP Operational Overview and the TCP Finite State Machine (FSM) http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm
http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm http://tcpipgu ...