CF 13E. Holes 分块数组
题目:点这
跟这题BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 一模一样
分析:
分块数组入门题。
具体的可以学习这篇博文以及做国家集训队2008 - 苏煜《对块状链表的一点研究》这篇论文上面的几道题目。
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue /******** program ********************/ const int MAXN = 1e5+5; int fa[MAXN],po[MAXN],sz[MAXN],a[MAXN],n,m;
int end[MAXN]; void make(int x){
int y = x+a[x];
if(y>n){
end[x] = x;
po[x] = n+1;
sz[x] = 1;
}else{
if(fa[x]==fa[y]){
end[x] = end[y];
po[x] = po[y];
sz[x] = sz[y]+1;
}else{
end[x] = x;
po[x] = y;
sz[x] = 1;
}
}
} void change(int x,int y){
a[x] = y;
for(int i=x;i;i--)
if(fa[i]==fa[x])
make(i);
else
break;
} void ask(int x){
int s = end[x];
int ans = 0;
for(int i=x;i<=n;i=po[i]){
ans += sz[i];
s = end[i];
}
printf("%d %d\n",s,ans);
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif RD2(n,m); int block_size = sqrt(n*1.0);
rep1(i,n){
RD(a[i]);
fa[i] = i / block_size;
} for(int i=n;i;i--)
make(i); int x,y,op;
while(m--){
RD2(op,x);
if(op==0){
RD(y);
change(x,y);
}else
ask(x);
} return 0;
}
CF 13E. Holes 分块数组的更多相关文章
- CF 13E Holes
Holes 题意:现在有一排洞,每个洞有一个弹力,能弹到ai之后的洞,球会弹到这个排的外面,现在有2个操作,0 a b 将第a个洞的弹力设为b, 1 a 将球放入第a个洞,求输出进洞的次数 和 弹出这 ...
- CodeForces 13E. Holes 分块处理
正解是动态树,太难了,仅仅好分块处理水之.看了看status大概慢了一倍之多.. 分块算法大体就是在找一个折衷点,使得查询和改动的时间复杂度都不算太高,均为o(sqrt(n)),所以总的时间复 ...
- codeforces 13E . Holes 分块
题目链接 nextt数组表示这个位置的下一个位置. cnt数组表示这个位置 i 到nextt[i]可以弹几次. end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里. 然后就看代码吧. # ...
- CF 13E Holes 【块状链表】
题目描述: 一条直线上n个点,每个点有个“弹力”,可以把当前位置x上面的ball弹到x+a[x]上面. 两种操作 0. 修改a处的弹力值,编程b 1. 询问a点的ball经过多少次能跳出n个点外(就是 ...
- 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 ...
- 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 13EE. Holes(分块&动态树)
E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input output ...
- CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序
http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...
- E. Holes(分块)
题目链接: E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input ...
随机推荐
- POJ3126 Prime Path
http://poj.org/problem?id=3126 题目大意:给两个数四位数m, n, m的位数各个位改变一位0 —— 9使得改变后的数为素数, 问经过多少次变化使其等于n 如: 10331 ...
- POJ 2481 Cows (数组数组求逆序对)
题目链接:http://poj.org/problem?id=2481 给你n个区间,让你求每个区间被真包含的区间个数有多少,注意是真包含,所以要是两个区间的x y都相同就算0.(类似poj3067, ...
- hibernate id生成器配置
1.uuid配置 <id name="tomdId" type="java.lang.String"> <column name=" ...
- swfupload用法总结
<script src="${base}/thirdparty/swfupload/swfupload.js" type="text/javascript" ...
- cocos2d-x 读取.plist文件
转自:http://blog.csdn.net/hgplan/article/details/8629904 在cocos2d-x中可以用.plist格式的文件来保存数据,它是XML文件格式的一种,在 ...
- ubuntu 15.04开放mysql远程连接
首先查看端口是否打开 netstat -an|grep 3306 此图为开启3306端口的截图,之前显示为. . . 127.0.0.1:3306 . . . 打开mysql配置文件vi /etc/m ...
- codeforces 468B 2-sat
今天明确了2-SAT; 表示对一对整数之间的关系是否存在 #include<cstdio> #include<algorithm> #include<iostream&g ...
- delphi 选中的展开0级 子级不展开
TreeView1.Selected.Expand(False); //选中的展开0级 子级不展开 TreeView1.Selected.Expand(True); //全部展开 来自为知笔记(Wiz ...
- oc-12-NSString 类简单介绍及用法
// 11-[掌握]NSString 类简单介绍及用法 #import <Foundation/Foundation.h> int main(int argc, const char * ...
- inux2.6.xx内核代码分析( 72节)
http://blog.csdn.net/ustc_dylan/article/category/469214