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 ...
随机推荐
- (转)C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上
原文地址:http://www.cnblogs.com/08shiyan/archive/2011/04/14/2015758.html /********************** * 课题:将窗 ...
- 利用sql里的xpath生成表格
SELECT (SELECT * from Common.Common_Setup_CityData FOR XML PATH('tr'), TYPE).query(' for $item ...
- WPF中timer的使用
Timer控件/ System.Timers.Timer 不能用于WPF中.在WPF中,定时器为 DispatcherTimer. 使用方法如下: private DispatcherTimer ti ...
- JS赋值传递的问题
根据值的类型是基本类型值还是复杂类型的值在传递时会有不同. JS函数的参数传递是按值传递,基本类型值传递的是副本,复杂类型值传递的是引用.从而会影响原来的值,不会改变原来的复制前的引用. functi ...
- 端口扫描器之java实现
端口扫描器之java实现 import java.net.*;import java.io.*;import java.awt.*;import java.awt.event.*;import j ...
- Android Studio之build.gradle小技巧
一: 当你工程引用android 的support包的时候,常常会这样写: dependencies { compile 'com.android.support:recyclerview-v7:22 ...
- Android 软键盘小知识点
chatText = (EditText) findViewById(R.id.chatText); chatText.setOnKeyListener(new OnKeyListener() { p ...
- 《小猪CMS(PigCms)多用户微信营销服务平台系统V6.1完美破解至尊版带微用户管理CRM+微信支付》
<小猪CMS(PigCms)多用户微信营销服务平台系统V6.1完美破解至尊版带微用户管理CRM+微信支付> 之前发布了不少微赢的多用户微信网站源码,今天为我的小伙伴们准备的是功能非常强悍, ...
- 树莓派设置成无线路由(AP)
1.安装需要的包 sudo apt-get install hostpad uhdcpd 2.配置/etc/network/interfaces文件 配置wlan0为静态地址 格式如下: iface ...
- Oracle EBS-SQL (BOM-9):检查系统BOM总数.sql
SELECT ITM.SEGMENT1 物料编码 ,ITM.DESCRIPTION 物料描述 ...