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 ...
随机推荐
- 深入探究frame和bounds的区别以及setbounds使用
[转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...
- srcelement、parentElement
srcElement 是Dom事件中的事件最初指派到的元素. 比如有一个div,里面有一个按钮.你响应div的onclick事件,但实际上,你单击的只是它内部的按钮,那么,srcElement指向的, ...
- Linux平台部署varnish 高性能缓存服务器
一:varnish部署前准备: 1.1相关软件以及系统,web服务 系统要求:Centos 6(以上) (64位) 相关中间件:varnish-4.0.2 1.2相关系统依赖包安装检查准备 1.2.1 ...
- mongod的主要参数解释
mongod的主要参数有:
- Global.asax.cs介绍
转载 http://www.cnblogs.com/tech-bird/p/3629585.html ASP.NET的配置文件 Global.asax--全局应用程序文件 Web.config--基 ...
- UVaLive 7375 Hilbert Sort (递归,四分图,模拟)
题意:告诉你一条希尔伯特曲线的大小,然后给你n 个人,及n 个人的坐标,你的起点是左下角,终点是右下角,按照希尔伯特的曲线去走,按照这个顺序给n个人排序, 按顺序输出每个人的名字! 析:这就是一个四分 ...
- 计算两个日期相隔的天数(jodd)
public static void main(String[] args) throws ParseException { System.out.println(TimeUtil.dayOfYear ...
- IE取消访问剪贴板设置
1. 启动IE. 2. Internet选项. 3. “安全”选项卡. 4. 自定义级别. 5. “安全设置-Internet区域”->脚本->允许对剪贴板进行编程访问(启用)
- java堆栈
一.堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令) 2.jvm只有一个堆区(heap)被所有线程共享,堆中不存放基本类型和对象引用,只存 ...
- checked 选中
<input type="radio" name="singleAnswer" value="0" <s:property va ...