题目链接

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. 利用DreamweaverCS5制作一个含有动态标题的教程

    DreamweaverCS5怎么制作一个含有动态标题?做一个网页就先要做一个标题,一个好标题会让网页让人印象深刻,有动态的标题会让网页更生动,下面我就介绍一下怎么制作一个含有动态的标题   做一个网页 ...

  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. 远程访问数据库查询数据量一大就Hang

    最近刚为客户升级了一套Oracle Database,一切进展顺利,眼看就要顺利验收时,发现有部分客户端软件连接新版本数据库时会Hang,问题非常诡异. 系统环境如下 升级前的环境OS:Windows ...

  4. 浅谈:SAMBA配置设置

      通过以下命令安装samba: yum install -y samba samba拥有三个服务,分别是: smbd 提供文件及打印共享功能,使用139.445端口 nmbd 提供NetBIOS支持 ...

  5. 【转】这些隐藏在苹果iPhone当中的内置代码你是否知道?

    原文地址:http://www.ithome.com/html/iphone/200569.htm 每一部手机都有一些内置的隐藏代码,我们称之为“指令”,这些代码加在一起就叫做“指令集”.当然这些代码 ...

  6. NSURLSessionDownloadTask 下载文件

    -(void)RequestdataUI:(NSString*)ImageURL imageName:(NSString*)imageName{ NSURL *url = [NSURL URLWith ...

  7. sed使用详解

    sed :Stream EDitor(流编辑器) sed :模式空间(默认不编辑源文件,仅对模式空间中数据做处理) sed [options] 'AddressCommand' file ... -n ...

  8. MySQL常用命令及操作

    1.登录与退出    1)登录        windows下直接在DOS命令窗口用root用户登录输入mysql回车;        linux下输入使用PUTTY连接mysql的服务器,然后输入: ...

  9. 运用Hibernate-Tools自动生成Java类和schema时,出现not found while looking for property...异常

    问题描述: 在使用Hibernate-tools时出现not found while looking for property...(具体信息省略). 问题分析: 我找到出错对应的hbm.xml文件, ...

  10. jquery中的on事件

    on()函数用于为指定元素的一个或多个事件绑定事件处理函数. 从jQuery 1.7开始,on()函数提供了绑定事件处理程序所需的所有功能,用于统一取代以前的bind(). delegate(). l ...