题目链接

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 分块的更多相关文章

  1. CodeForces 13E. Holes 分块处理

    正解是动态树,太难了,仅仅好分块处理水之.看了看status大概慢了一倍之多..     分块算法大体就是在找一个折衷点,使得查询和改动的时间复杂度都不算太高,均为o(sqrt(n)),所以总的时间复 ...

  2. codeforces 13EE. Holes(分块&amp;动态树)

    E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input output ...

  3. 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 ...

  4. CF 13E. Holes 分块数组

    题目:点这 跟这题BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊  一模一样 分析: 分块数组入门题. 具体的可以学习这篇博文以及做国家集训队2008 - 苏煜<对块状链表的一 ...

  5. (分块)Holes CodeForces - 13E

    题意 n(n≤105)个洞排成一条直线,第ii个洞有力量值ai,当一个球掉进洞ii时就会被立刻弹到i+ai,直到超出n.进行m(m≤105)次操作: ·修改第i个洞的力量值ai. ·在洞xx上放一个球 ...

  6. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

  7. CodeForces 13E 分块

    题目链接:http://codeforces.com/problemset/problem/13/E 题意:给定n个弹簧和每个弹簧初始的弹力a[].当球落在第i个位置.则球会被弹到i+a[i]的位置. ...

  8. CF 13E Holes

    Holes 题意:现在有一排洞,每个洞有一个弹力,能弹到ai之后的洞,球会弹到这个排的外面,现在有2个操作,0 a b 将第a个洞的弹力设为b, 1 a 将球放入第a个洞,求输出进洞的次数 和 弹出这 ...

  9. 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 ...

随机推荐

  1. android经典Demo(转载)

    一篇不错的资源博文,转载分享给大家:   1.Android团队提供的示例项目  如果不是从学习Android SDK中提供的那些样例代码开始,可能没有更好的方法来掌握在Android这个框架上开发. ...

  2. DBSCAN(Density-based spatial clustering of applications with noise)

    Density-based spatial clustering of applications with noise (DBSCAN) is a data clustering algorithm ...

  3. SQL Server 创建作业系列问题

    一.从IClassFactory为CLSID为{AA40D1D6-CAEF-4A56-B9BB-D0D3DC976BA2}的COM组件创建实例失败. 尊重原著作:本文转载自http://www.hao ...

  4. Oracle GoldenGate配置异构数据库数据传输(oracle到sqlserer)的dml操作(带pump进程)

    实验环境:os01:Red Hat Enterprise Linux Server release 5.1 (32位)db01:oracle 10.2.0.1.0 os02:Windows 7 (32 ...

  5. Qt使用快捷键

    在说快捷键之前先来说一个QtCreator调试的过程中经常发生的一个问题. 问题描述: 用QtCreator建立了一个纯C++的项目,但是在F5调试时,竟然提示ptrace不允许的操作,修改工程配置为 ...

  6. 使用HAProxy、PHP、Redis和MySQL支撑每周10亿请求

    在公司的发展中,保证服务器的可扩展性对于扩大企业的市场需要具有重要作用,因此,这对架构师提出了一定的要求.Octivi联合创始人兼软件架构师Antoni Orfin将向你介绍一个非常简单的架构,使用H ...

  7. 表格(table) 插件:支持当前行增行、删除。使用事件委托

    最近做一个项目,需要对表格进行增行和删行. 研究了一下jquery操作dom的方法和事件委托原理,下面是我编写的例子,源码传上,欢迎高手指点. 功能: 支持在指定行下面增行: 支持删行指定行: 增行. ...

  8. Thinkphp3.2使用scws中文分词 提取关键词

    SCWS 是 Simple Chinese Word Segmentation 的首字母缩写(即:简易中文分词系统).1.下载scws官方提供的类(这里使用的是pscws第四版的)http://www ...

  9. 【Java 小实验】重写(覆写 Override)返回值类型能不能相同

    背景 每次看到重写那里写着: 重写机制是指子类的方法的方法名.参数表.返回值与父类中被重写的方法都相同,而方法体不同. 而重载是: 方法名与父类中的相同,而参数表不同,则属于同名方法的重载. 本来的感 ...

  10. rpm安装软件(需管理员权限)

    常用命名规范 linux-1.2.0-30.e16.i686.rpm rpm基本命令 安装rpm -i software.rpm 卸载rpm -e software 升级rpm -U software ...