HYSBZ 2002 分块
题目链接: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 分块的更多相关文章
- Bounce 弹飞绵羊 HYSBZ - 2002 分块
//预处理出以这个点为起点并跳出这个块的次数和位置 //更新一个点的弹力系数可以只更新这个点以及这个块内之前的点 #include<stdio.h> #include<algorit ...
- HYSBZ 2957 分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 题意:中文题面 思路: 来自此博客 首先明确问题,对于每栋楼房的斜率K=H/X,问题 ...
- HYSBZ_2002_分块
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块基础题,初次接触,很巧妙. OJ好像挂了,没法提交. #include<iostre ...
- Bounce 弹飞绵羊
Bounce 弹飞绵羊 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块 将整个大区间分成若干块,每个点维护到下一个块需要跳的次 ...
- bzoj 刷题计划~_~
bzoj 2818 两个互质的数的gcd=1,所以他们同时乘一个素数那么他们的gcd=这个素数,所以枚举素数p找n/p以内有多少对互质数,用欧拉函数. bzoj 2809 可并堆,对于每一个子树显然是 ...
- LCT(link cut tree) 动态树
模板参考:https://blog.csdn.net/saramanda/article/details/55253627 综合各位大大博客后整理的模板: #include<iostream&g ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 分块
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOn ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊(分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 思路:不会LCT,就只好用分块了. 将这n个数分成根号n块,对于每一块中的每一个数,处 ...
- BZOJ 2002:Bounce 弹飞绵羊(分块)
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 14944 Solved: 7598 [Su ...
随机推荐
- Alpha阶段第九次Scrum Meeting
情况简述 Alpha阶段第九次Scrum Meeting 敏捷开发起始时间 2016/11/2 00:00 敏捷开发终止时间 2016/11/3 00:00 会议基本内容摘要 汇报进度,安排工作 参与 ...
- java支持跨平台获取cpuid、主板id、硬盘id、mac地址 (兼容windows、Linux)
windows: package cn.net.comsys.helper.system.info; import java.io.BufferedReader; import java.io.F ...
- Property和attribute的区别[转]
Attribute和Property都可以翻译成“属性”,有的地方用Attribute表示“属性”,有的地方又在用Property,初 学者常常在这两个单词间“迷失”,甚至认为二者没有区别,是一样的. ...
- HTML补充
补充一: 让DIV 自动居中 width:980px;margin:0 auto; 补充二: 内敛标签: inline #块级标签转换成内联标签. block #变成块级. inline-block ...
- [NHibernate]存储过程的使用(三)
目录 写在前面 文档与系列文章 查询 总结 写在前面 前面的文章介绍了在nhibernate中使用存储过程进行增删改的操作,当然查询也是可以的,在nhibernate中也可以执行任意的存储过程.本篇文 ...
- WindowsPhone8.1RT建立空白应用挂起没反应的解决方案
wp8.1下, 建立空白应用后遇到的问题:想要实现保存.提取数据都无法成功 在退出程序后无法进入到OnNavigatedFrom()中去. 网上说要手动的Invoke OnSuspending事件. ...
- socket编程热身程序
/*server.c*/ #include <stdio.h> #include <arpa/inet.h> #include <sys/types.h> /* S ...
- godaddy域名使用DNSPod做DNS解析图文教程
考虑到很多朋友看到英文就很头痛,在godaddy解析域名也不怎么方便,我们需要把在godaddy注册的域名,使用国内的DNS服务器,全部都是免费的哦. 首先打开www.dnspod.cn 用自己的常 ...
- 修复 ThinkPHP3.2.3 抛出异常模块的一个BUG,关闭字段缓存功能
使用 ThinkPHP3.2.3 遇到一个奇怪的问题,正式环境上报错,提示 “页面错误!请稍后再试~” 为了查看到底出啥错误,哪里出错,于是在入口文件中加了一段代码,开启调试: defined('AP ...
- Mac Pro 安装 Sublime Text 3,个性化设置,主题 和 插件 收藏
1.到官网下载安装包 http://www.sublimetext.com/3 2.附注册码一枚 Sublime Text 3 3126 —– BEGIN LICENSE —– Alexey Plut ...