题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002

题意:中文题面

思路:考虑分块,每个位置维护一个跳出该块需要的步数cnt[],和跳出该块后到达下一块的哪个位置to[]。

关于修改操作:直接修改所在块的左端点到修改的位置。 然后需要逆序修改。因为后面的位置的值会影响到前面位置的值。

关于询问操作:直接暴力计算即可。

#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<queue>
#include<math.h>
#include<time.h>
#include<vector>
#include<iostream>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
int belong[MAXN], block, num, L[MAXN], R[MAXN];
int n, q;
int a[MAXN], cnt[MAXN], to[MAXN];
void build(){
block = (int)sqrt(n + 0.5);
num = n / block; if (n%block){ num++; }
for (int i = ; i <= num; i++){
L[i] = (i - )*block + ; R[i] = i*block;
}
R[num] = n;
for (int i = ; i <= n; i++){
belong[i] = ((i - ) / block) + ;
}
for (int i = num; i>; i--){
for (int j = R[i]; j >= L[i]; j--){
if (j + a[j]>R[i]){
cnt[j] = ; to[j] = min(n+,j + a[j]);
}
else{
cnt[j] = cnt[j + a[j]] + ; to[j] = min(n+,to[j + a[j]]);
}
}
}
}
void modify(int pos, int val){
a[pos] = val;
for (int i = pos; i >= L[belong[pos]]; i--){
if (i + a[i]>R[belong[pos]]){
cnt[i] = ; to[i] = min(i + a[i], n + );
}
else{
cnt[i] = cnt[i + a[i]] + ; to[i] = min(to[i + a[i]], n + );
}
}
}
int query(int pos){
int ans = ;
for (int i = pos; i <= n; i = to[i]){
ans += cnt[i];
}
return ans;
}
int main(){
//#ifdef kirito
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
//#endif
// int start = clock();
while (~scanf("%d", &n)){
for (int i = ; i <= n; i++){ scanf("%d", &a[i]); }
build(); scanf("%d", &q);
int type, pos, v;
for (int i = ; i <= q; i++){
scanf("%d", &type);
if (type == ){
scanf("%d", &pos); pos++; printf("%d\n", query(pos));
}
else{
scanf("%d%d", &pos, &v); pos++; modify(pos, v);
}
}
}
//#ifdef LOCAL_TIME
// cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
return ;
}

HYSBZ 2002 分块的更多相关文章

  1. Bounce 弹飞绵羊 HYSBZ - 2002 分块

    //预处理出以这个点为起点并跳出这个块的次数和位置 //更新一个点的弹力系数可以只更新这个点以及这个块内之前的点 #include<stdio.h> #include<algorit ...

  2. HYSBZ 2957 分块

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 题意:中文题面 思路: 来自此博客 首先明确问题,对于每栋楼房的斜率K=H/X,问题 ...

  3. HYSBZ_2002_分块

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块基础题,初次接触,很巧妙. OJ好像挂了,没法提交. #include<iostre ...

  4. Bounce 弹飞绵羊

    Bounce 弹飞绵羊 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块 将整个大区间分成若干块,每个点维护到下一个块需要跳的次 ...

  5. bzoj 刷题计划~_~

    bzoj 2818 两个互质的数的gcd=1,所以他们同时乘一个素数那么他们的gcd=这个素数,所以枚举素数p找n/p以内有多少对互质数,用欧拉函数. bzoj 2809 可并堆,对于每一个子树显然是 ...

  6. LCT(link cut tree) 动态树

    模板参考:https://blog.csdn.net/saramanda/article/details/55253627 综合各位大大博客后整理的模板: #include<iostream&g ...

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

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

  8. BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊(分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 思路:不会LCT,就只好用分块了. 将这n个数分成根号n块,对于每一块中的每一个数,处 ...

  9. BZOJ 2002:Bounce 弹飞绵羊(分块)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 14944  Solved: 7598 [Su ...

随机推荐

  1. 关于分页接口设计(下拉刷新上拉加载原理,解决page count请求重复数据的问题)

  2. WinForm------SimpleButton去掉点击时的边框

    设置属性

  3. 什么是pe系统

    Winpe全称 Windows Preinstall Environment,即“Windows 预安装环境”.是一个用于Windows 安装准备的最小操作系统. 基于保护模式下运行Windows X ...

  4. 11月3日上午PHP练习《投票》

    1.建立数据库 表1:DiaoYanTiMu 表2:DiaoYanXuanXiang 2.页面 页面1:投票首页 <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  5. sublime2使用jshint

    合理配置Jshint可以帮助写出高质量的代码,通过sublime2插件 JSHint Gutter 可以迅速提供开发效率和减少bug的个数. 1.安装JSHint Gutter插件 sublime2按 ...

  6. 入门: 使用JNI 从C++代码中调用Java的静态方法

    开发环境: 操作系统: (uname -a output)  Linux ubuntu 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC ...

  7. JS中数组Array的用法{转载}

    js数组元素的添加和删除一直比较迷惑,今天终于找到详细说明的资料了,先给个我测试的代码^-^var arr = new Array();arr[0] = "aaa";arr[1] ...

  8. thinkphp3.2.3之自动完成的实现

    有时候,我们希望系统能够帮我们自动完成一些功能,比如自动为密码加密,忽略空等,这个时候我们就需要利用到自动完成(填写)的功能. ThinkPHP 模型层提供的数据处理方法,主要用于数据的自动处理和过滤 ...

  9. ThinkPHP之OAuth2.0环境搭建

    几个比较好的超链接 1.http://www.tuicool.com/articles/u6beUju 2.http://leyteris.iteye.com/blog/1483403

  10. 【Alpha版本】冲刺阶段——Day 2

    我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...