正解是动态树,太难了,仅仅好分块处理水之。看了看status大概慢了一倍之多。。

    分块算法大体就是在找一个折衷点,使得查询和改动的时间复杂度都不算太高,均为o(sqrt(n)),所以总的时间复杂度为o(m*sqrt(n))。

    分块的大体思想就是将整段区间分成sqrt(n),每次改动影响所在段内的sqrt(n)个点。每次查询遍历sqrt(n)段,然后搞出一些事情。

    对于此题,首先说明几个数组的含义:

    cnt[i]的意义为从i点開始跳出其所在段所须要的步数。

    goal[i]的意义为从i点開始所经历的最后一个点。

    jmp[i]的意义为从i点開始跳出所在段之后第一个到达点。

    明确了这几个意义之后看代码就好了,文字太无力。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <ctime>
#include <iomanip> #pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-6)
#define LL long long
#define ULL unsigned long long
#define _LL __int64
#define INF 0x3f3f3f3f
#define Mod 1000000007 using namespace std; const int MAXN = 100010,BLOCK = sqrt(100010); int jmp[MAXN],cnt[MAXN],goal[MAXN],val[MAXN]; void Updata(int x,int y,int n)
{
if(y > n)
{
jmp[x] = MAXN;
cnt[x] = 1;
goal[x] = x;
}
else if(x/BLOCK*BLOCK == y/BLOCK*BLOCK)
{
jmp[x] = jmp[y];
cnt[x] = cnt[y]+1;
goal[x] = goal[y];
}
else
{
jmp[x] = y;
cnt[x] = 1;
goal[x] = y;
}
} void Cal(int x)
{
int ans = 0,f; while(x != MAXN)
{
f = goal[x];
ans += cnt[x];
x = jmp[x];
} printf("%d %d\n",f,ans); } int main()
{
int i,j,u,v,n,m,ord,L; scanf("%d %d",&n,&m); for(i = 1;i <= n; ++i)
scanf("%d",&val[i]); for(i = n;i >= 1; --i)
Updata(i,i+val[i],n); while(m--)
{
scanf("%d",&ord); if(ord)
{
scanf("%d",&u);
Cal(u);
}
else
{
scanf("%d %d",&u,&v);
val[u] = v;
L = u/BLOCK*BLOCK;
for(i = u;i >= L; --i)
Updata(i,i+val[i],n);
}
} return 0;
}

CodeForces 13E. Holes 分块处理的更多相关文章

  1. codeforces 13E . Holes 分块

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

  2. codeforces 13EE. Holes(分块&amp;动态树)

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

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

  4. CF 13E. Holes 分块数组

    题目:点这 跟这题BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊  一模一样 分析: 分块数组入门题. 具体的可以学习这篇博文以及做国家集训队2008 - 苏煜<对块状链表的一 ...

  5. (分块)Holes CodeForces - 13E

    题意 n(n≤105)个洞排成一条直线,第ii个洞有力量值ai,当一个球掉进洞ii时就会被立刻弹到i+ai,直到超出n.进行m(m≤105)次操作: ·修改第i个洞的力量值ai. ·在洞xx上放一个球 ...

  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 13E 分块

    题目链接:http://codeforces.com/problemset/problem/13/E 题意:给定n个弹簧和每个弹簧初始的弹力a[].当球落在第i个位置.则球会被弹到i+a[i]的位置. ...

  8. CF 13E Holes

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

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

随机推荐

  1. eclipse中使用maven插件的时候,运行run as maven build/clean的时候报错

    -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a ...

  2. 清华集训2014 day1 task2 主旋律

    题目 这可算是一道非常好的关于容斥原理的题了. 算法 好吧,这题我毫无思路,直接给正解. 首先,问题的正面不容易求,那么就求反面吧: 有多少种添加边的方案,使得这个图是DAG图(这里及以下所说的DAG ...

  3. mysql 创建表 create table详解

      1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...

  4. highcharts dynamic change line color

    mouseOut: function(){ this.series.graph.attr({"stroke","#ccc"}) }

  5. 【Cocos2d-x游戏引擎开发笔记(25)】XML解析

    原创文章,转载请注明出处:http://blog.csdn.net/zhy_cheng/article/details/9128819 XML是一种非常重要的文件格式,由于C++对XML的支持非常完善 ...

  6. UVA 10317 - Equating Equations (背包)

    Problem F Equating Equations Input: standard input Output: standard output Time Limit: 6 seconds Mem ...

  7. 在Windows下搭建C++11 编译环境(附下载,包括mingw-build,TDM-GCC, nuwen MinGW Distro)

    由于现实的一些原因,并不是所有人都能很方便的享受到C++11 特性.特别是C++ Primer 第五版 和 The C++ Programming Language 第四版等全面C++ 11 铺开以后 ...

  8. C++能在三个地方创造对象,而Delphi只有一个地方

    C++能在堆栈.堆.资料区创造对象. 但是Delphi只能在堆上创造对象

  9. os内存使用管理之unix-AIX篇

    os内存使用管理之unix-AIX篇 未完待补充.....

  10. 重操JS旧业第六弹:基本类型包装

    在前面已经知道js中的类型有boolean,string,number,undefined,function,object,其中boolean,number,string为值类型.所谓的基本类型包装, ...