codeforces 13E . Holes 分块
nextt数组表示这个位置的下一个位置。
cnt数组表示这个位置 i 到nextt[i]可以弹几次。
end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里。
然后就看代码吧。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e5 + ;
int a[maxn], cnt[maxn], nextt[maxn], pos[maxn], block[maxn], n;
void update(int x, int y) {
if(y >= n) {
nextt[x] = n+;
cnt[x] = ;
pos[x] = x;
} else {
if(block[x] == block[y]) {
nextt[x] = nextt[y];
cnt[x] = cnt[y] + ;
} else {
nextt[x] = y;
cnt[x] = ;
}
pos[x] = pos[y];
}
}
void query(int x) {
int i, ans = ;
for(i = x; ; i = nextt[i]) {
ans += cnt[i];
if(nextt[i] >= n) {
i = pos[i];
break;
}
}
printf("%d %d\n", i+, ans);
}
int main()
{
int m, sign, x, y;
cin>>n>>m;
int BLOCK = sqrt(n);
for (int i = ; i < n; i++) {
scanf("%d", a + i);
block[i] = i / BLOCK;
}
for (int i = n-; i >= ; i--) {
update(i, i + a[i]);
}
while (m--) {
scanf("%d", &sign);
if(sign) {
scanf("%d", &x);
query(x-);
} else {
scanf("%d%d", &x, &y);
x--;
a[x] = y;
int l = block[x] * BLOCK;
int r = l + BLOCK;
r = min(n, r);
for(int i = r-; i >= l; i--) {
update(i, i + a[i]);
}
}
}
return ;
}
codeforces 13E . Holes 分块的更多相关文章
- CodeForces 13E. Holes 分块处理
正解是动态树,太难了,仅仅好分块处理水之.看了看status大概慢了一倍之多.. 分块算法大体就是在找一个折衷点,使得查询和改动的时间复杂度都不算太高,均为o(sqrt(n)),所以总的时间复 ...
- codeforces 13EE. Holes(分块&动态树)
E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input output ...
- CodeForces - 13E(分块)
Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for on ...
- CF 13E. Holes 分块数组
题目:点这 跟这题BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 一模一样 分析: 分块数组入门题. 具体的可以学习这篇博文以及做国家集训队2008 - 苏煜<对块状链表的一 ...
- (分块)Holes CodeForces - 13E
题意 n(n≤105)个洞排成一条直线,第ii个洞有力量值ai,当一个球掉进洞ii时就会被立刻弹到i+ai,直到超出n.进行m(m≤105)次操作: ·修改第i个洞的力量值ai. ·在洞xx上放一个球 ...
- Codeforces Beta Round #13 E. Holes 分块暴力
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...
- CodeForces 13E 分块
题目链接:http://codeforces.com/problemset/problem/13/E 题意:给定n个弹簧和每个弹簧初始的弹力a[].当球落在第i个位置.则球会被弹到i+a[i]的位置. ...
- CF 13E Holes
Holes 题意:现在有一排洞,每个洞有一个弹力,能弹到ai之后的洞,球会弹到这个排的外面,现在有2个操作,0 a b 将第a个洞的弹力设为b, 1 a 将球放入第a个洞,求输出进洞的次数 和 弹出这 ...
- CodeForces - 13E
Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for on ...
随机推荐
- ArcGIS for Android学习(一)
GIS的开发中,什么时候都少不了地图操作.ArcGIS for Android中,地图组件就是MapView,MapView是基于Android中ViewGroup的一个类(参考),也是ArcGIS ...
- RDLC报表系列(二) 行分组
接上一篇文章的内容,今天来说的是行分组.还是打开demo1.rdlc界面,拖入一个文本框和表 1.在表中随便选择一个字段,不然在添加行组的时候不会自动提示.我这里是选择的Dept 2.在下面的行组中右 ...
- Http权威指南笔记(二) Http状态码大全
100~199—信息状态码 200~299—成功状态码 客户端发请求时,这些请求通常都是成功的. 300~399—重定向状态码 重定向状态码告知客户端使用代替位置来访问他们所感兴趣的资源. 400~4 ...
- C# 过滤特殊字符
. /// <summary> /// 过滤不安全的字符串 /// </summary> /// <param name="Str"></ ...
- C++中数字与字符串之间的转换,别人的,
C++中数字与字符串之间的转换 1.字符串数字之间的转换 (1)string --> char * string str("OK"); char * p = st ...
- 用OpenCV实现Otsu算法
算法的介绍 otsu法(最大类间方差法,有时也称之为大津算法)使用的是聚类的思想,把图像的灰度数按灰度级分成2个部分,使得两个部分之间的灰度值差异最大,每个部分之间的灰度差异最小,通过方差的计算来寻找 ...
- 关于各种数据库 Insert时同时取到Id的操作
对数据库的操作,在Insert的同时获取到Id,保证原子性操作.而不是,先取Id,然后再插入到数据库等操作. Oracle: 使用Oracle自带的 Returning into 语句,具体代码示例如 ...
- HTTP缓存缓存机制
http协议无状态,所以缓存设定从两方面考虑.客户端浏览器和服务器端. 浏览器端实现过期机制. 服务器端实现验证机制. 缓存机制. 为了减轻服务器负担,也减少网络传输数量.http1.0定义了Expi ...
- pycharm的激活
——————转———— Pycharm5注册方式 0x1 ,安装 0x2 , 调整时间到2038年. 0x3 ,申请30天试用 0x4, 退出pycharm 0x5, 时间调整回来. ##注册方法 ...
- 2012年的MBP准备升级
2012年买的MBP MD313要升级啦! 原因是4G内存在升级10.9巨浪后,无论是登录还是打开程序都比较慢,看内存使用使用基本上是满了,因此有了升级内存的想法. 首先想到的是看最大容量,16G,所 ...