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 ...
随机推荐
- BAT-使用BAT方法清理系统垃圾
@echo offecho 正在清理......del /f /s /q %systemdrive%\*.tmpdel /f /s /q %systemdrive%\*._mpdel /f /s /q ...
- Spring入门(8)-基于Java配置而不是XML
Spring入门(8)-基于Java配置而不是XML 本文介绍如何应用Java配置而不是通过XML配置Spring. 0. 目录 声明一个简单Bean 声明一个复杂Bean 1. 声明一个简单Bean ...
- [iOS UI进阶 - 3.1] 触摸事件的传递
A.事件的产生和传递 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中UIApplication会从事件队列中取出最前面的事件,并将事件分发下去以便处理,通常,先发 ...
- CommandLine 和 Options
用到的jar包 <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli& ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- ASP.NET forms凭据设置和跳转的几种方法
string user = "userName"; //默认的第1种,超时时间是在web.cofig中forms设置的timeout,单位是分钟,生成的cookie和凭证超时时间一 ...
- 汇编语言(学习笔记-----[bx]和loop)
1.[bx]是什么?? 和[0]有些类似,[0]表示内存单元,它的偏移地址是0 [bx]同样也表示一个内存单元,它的偏移地址在bx中,mov ax,[bx] (字) mov ...
- WinDbug之DUMP蓝屏分析
Microsoft (R) Windows Debugger Version 6.2.8400.0 X86Copyright (c) Microsoft Corporation. All rights ...
- insertion sort
1.insertion sort #include <stdio.h> #include <time.h> #include <stdlib.h> #define ...
- 【v2.x OGE教程 19】 引擎状态控制
1.手机button监听 OGE中提供了在BaseGameLauncher(GameLauncher的父类)和IScene(Scene实现的接口)中定义了onKeyUp和onKeyDown的方法.使得 ...