任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2002

2002: [Hnoi2010]Bounce 弹飞绵羊

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 14824  Solved: 7515
[Submit][Status][Discuss]

Description

某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏。游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系数ki,当绵羊达到第i个装置时,它会往后弹ki步,达到第i+ki个装置,若不存在第i+ki个装置,则绵羊被弹飞。绵羊想知道当它从第i个装置起步时,被弹几次后会被弹飞。为了使得游戏更有趣,Lostmonkey可以修改某个弹力装置的弹力系数,任何时候弹力系数均为正整数。

Input

第一行包含一个整数n,表示地上有n个装置,装置的编号从0到n-1,接下来一行有n个正整数,依次为那n个装置的初始弹力系数。第三行有一个正整数m,接下来m行每行至少有两个数i、j,若i=1,你要输出从j出发被弹几次后被弹飞,若i=2则还会再输入一个正整数k,表示第j个弹力装置的系数被修改成k。对于20%的数据n,m<=10000,对于100%的数据n<=200000,m<=100000

Output

对于每个i=1的情况,你都要输出一个需要的步数,占一行。

Sample Input

4
1 2 1 1
3
1 1
2 1 1
1 1

Sample Output

2
3

题意概括:略

解题思路:

在线的查询,神奇暴力算法分块!

记录每个点跳到下一分块的步数和每个点跳到下一分块的位置

AC code:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define ll long long int
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 2e5+;
inline ll read()
{
ll x = , f = ; char ch = getchar();
while(ch > '' || ch < '') {if(ch == '-')f = -; ch = getchar();}
while(ch >= '' && ch <= ''){x=x*+ch-''; ch = getchar();}
return x*f;
}
int N, M;
int block, cnt; ///分块的大小,分块的数量
int pt[MAXN], st[MAXN]; ///记录跳打下一个分块的位置 记录跳到下一个分块的步数
int K[MAXN];
int belong[MAXN]; ///记录当前的数属于第几个分块
int l[MAXN], r[MAXN]; ///记录每个分块的左右边界
inline int cal(int x)
{
int temp = ;
while(){
temp+=st[x];
if(!pt[x]) break; ///飞出去了
x = pt[x]; ///跳到下一个点
}
return temp;
}
int main()
{
N = read();
block = sqrt(N);
for(int i = ; i <= N; i++){
K[i] = read();
}
if(N%block) cnt = N/block+;
else cnt = N/block; for(int i = ; i <= cnt; i++){
l[i] = (i-)*block+; ///相当于退回前一个的右端点+1
r[i] = i*block;
}
r[cnt] = N; for(int i = ; i <= N; i++){
belong[i] = (i-)/block+;
} for(int i = N; i > ; i--){
if(i+K[i] > N) st[i] = ; ///飞出去了
else if(belong[i] == belong[i+K[i]]){ ///还没跳出当前分块
st[i] = st[i+K[i]]+; pt[i] = pt[i+K[i]];
}
else st[i] = , pt[i] = i+K[i]; ///跳到下一个分块
}
M = read();
int x, y, command;
for(int i = ; i <= M; i++){
command = read(), x = read();
x++;
if(command == ) printf("%d\n", cal(x));
else{
y = read();
K[x] = y;
for(int i = x; i >= l[belong[x]]; i--)
if(belong[i] == belong[i+K[i]]){ ///还没跳出当前分块
st[i] = st[i+K[i]]+; pt[i] = pt[i+K[i]];
}
else st[i] = , pt[i] = i+K[i]; ///跳到下一个分块
}
}
return ;
}

BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 【分块】的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (动态树LCT)

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

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

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆 ...

  8. bzoj 2002[Hnoi2010]Bounce 弹飞绵羊(分治分块)

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置 ...

  9. 洛谷 P3203 BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊

    题目描述 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装置设定初始弹力系 ...

随机推荐

  1. nyoj 1023——还是回文——————【区间dp】

    还是回文 时间限制:2000 ms  |  内存限制:65535 KB 难度:3   描述 判断回文串很简单,把字符串变成回文串也不难.现在我们增加点难度,给出一串字符(全部是小写字母),添加或删除一 ...

  2. js.css嵌入dll

    处理请求,返回 public ActionResult Get() { //传递一个部分名称 var n = Request["n"]; n = n.Replace('/', '. ...

  3. View视图调用控制器方法

    1.@using XXX.Controllers;//引用控制器 2. var otherController = DependencyResolver.Current.GetService<U ...

  4. CTF传送门

    https://www.zhihu.com/question/30505597详细见知乎 推荐书: A方向: RE for BeginnersIDA Pro权威指南揭秘家庭路由器0day漏洞挖掘技术自 ...

  5. PAT 1066 Root of AVL Tree

    #include <cstdio> #include <cstdlib> class Node { public: Node* L; Node* R; int height; ...

  6. oracle相关常识

    1.数据类型 VARCHAR2() NUMBER() DATE CLOB BLOB 2.复制表:create table tableName as select * from emp3.新增列:ALT ...

  7. Android 笔记之 R 文件

    Android笔记之R文件 h2{ color: #4abcde; } a{ color: blue; text-decoration: none; } a:hover{ color: red; te ...

  8. Shader Example

    //测试viewDir对顶点的影响Shader "Example/TestViewDir" { Properties{ _RimColor("Rim Color" ...

  9. 【起航计划 032】2015 起航计划 Android APIDemo的魔鬼步伐 31 App->Search->Invoke Search 搜索功能 Search Dialog SearchView SearchRecentSuggestions

    Search (搜索)是Android平台的一个核心功能之一,用户可以在手机搜索在线的或是本地的信息.Android平台为所有需要提供搜索或是查询功能的应用提 供了一个统一的Search Framew ...

  10. Mantis去掉登录界面的“注册一个新账号”链接

    Mantis1.1.2主界面提供了新账号注册功能,但是只能注册默认权限的帐号.不是很实用,那就干脆去掉吧. (1) 打开Mantis目录下的login_page.php和lost_pwd_page.p ...