题目:点这

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

  1. CF 13E Holes

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

  2. CodeForces 13E. Holes 分块处理

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

  3. codeforces 13E . Holes 分块

    题目链接 nextt数组表示这个位置的下一个位置. cnt数组表示这个位置 i 到nextt[i]可以弹几次. end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里. 然后就看代码吧. # ...

  4. CF 13E Holes 【块状链表】

    题目描述: 一条直线上n个点,每个点有个“弹力”,可以把当前位置x上面的ball弹到x+a[x]上面. 两种操作 0. 修改a处的弹力值,编程b 1. 询问a点的ball经过多少次能跳出n个点外(就是 ...

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

  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 13EE. Holes(分块&amp;动态树)

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

  8. CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序

    http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...

  9. E. Holes(分块)

    题目链接: E. Holes time limit per test 1 second memory limit per test 64 megabytes input standard input ...

随机推荐

  1. NSLog说明

    %@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x,%X 二进制整 ...

  2. thymeleaf中的th:each用法

    一.th:eath迭代集合用法: <table> <thead> <tr> <th>序号</th> <th>用户名</th ...

  3. 跟Android自带模拟器说拜拜,Mac Genymotion 使用心得

    今天看到网上一片文章点击打开链接,很是激动,套用原作者的话,性能卓越作为历史上最快的Android模拟器(没有之一),秒级开机关机速度足够让你膜拜了(粗略估计5-20s不等),我的Mac上面运行And ...

  4. Qt + CURL + mimetic 发送邮件(带附件)

    使用了大名鼎鼎的CURL 开源库,以及mimetic开源库. CURL支持N多协议.功能超强,但是不能直接发邮件附件,需要自己拼mime.太麻烦,于是乎~~ mimetic主要用于构造邮件mimeti ...

  5. [c++]this指针理解

    #include <iostream> using namespace std; /** * this 指针理解 */ class A{ int i; public: void hello ...

  6. sql,mybatis,javascript分页功能的实现

    用三种不同的方法实现多数据的分页功能.原生sql和mybatis的操作需要每次点击不同页数时都发送http请求,进行一次数据库查询,如果放在前端页面写js语句则不需要每次都请求一次,下面是三种不同的方 ...

  7. C语言根据日期取其位于一年中的第几天

    #include <iostream> #include <stdlib.h> using namespace std; bool isLeapYear( int iYear ...

  8. 安装Loopback网卡/回环网卡

    $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.LastIndexOf('\' ...

  9. Swift学习笔记三

    协议和扩展 在Objective-C中,协议是很常见也非常重要的一个特性,Swift中也保留了协议,语法略有变化. 用protocol关键字声明一个协议: protocol ExampleProtoc ...

  10. 将PHP作为Shell脚本语言使用

    我们都知道.PHP是一种非常好的动态网页开发语言(速度飞快.开发周期短--).可是仅仅有非常少数的人意识到PHP也能够非常好的作为编写Shell脚本的语言,当PHP作为编写Shell脚本的语言时,他并 ...