E. Holes

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/13/problem/E

Description

Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules:

There are N holes located in a single row and numbered from left to right with numbers from 1 to N. Each hole has it's own power (hole number i has the power ai). If you throw a ball into hole i it will immediately jump to hole i + ai, then it will jump out of it and so on. If there is no hole with such number, the ball will just jump out of the row. On each of the M moves the player can perform one of two actions:

Set the power of the hole a to value b.
    Throw a ball into the hole a and count the number of jumps of a ball before it jump out of the row and also write down the number of the hole from which it jumped out just before leaving the row.

Petya is not good at math, so, as you have already guessed, you are to perform all computations.

Input

The first line contains two integers N and M (1 ≤ N ≤ 105, 1 ≤ M ≤ 105) — the number of holes in a row and the number of moves. The second line contains N positive integers not exceeding N — initial values of holes power. The following M lines describe moves made by Petya. Each of these line can be one of the two types:

0 a b
    1 a

Type 0 means that it is required to set the power of hole a to b, and type 1 means that it is required to throw a ball into the a-th hole. Numbers a and b are positive integers do not exceeding N.

Output

For each move of the type 1 output two space-separated numbers on a separate line — the number of the last hole the ball visited before leaving the row and the number of jumps it made.

Sample Input

8 5
1 1 1 1 1 2 8 2
1 1
0 1 3
1 1
0 3 4
1 2

Sample Output

8 7
8 5
7 3

HINT

题意

有n个弹簧,每次扔个球,这个球可以弹到i+power[i]的位置

然后有两种操作

将第i个位置的弹簧的弹力改为b

将球扔到第i个位置,问这个球最后弹到了哪儿,这个球弹了几次?

题解:

分块暴力,块内暴力修改就好了,块外就直接指过去

暴力搞一搞就好了,这道题和hnoi2010弹飞绵羊这道题基本上是一样的

代码

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000010
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff;
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int power[maxn];
int block;
int cnt[maxn];
int end[maxn];
int next[maxn];
int n,m;
void update(int i,int j)
{
if(j>n)
{
next[i]=n+;
cnt[i]=;
end[i]=i;
}
else
{
if(i/block==j/block)
{
cnt[i]=cnt[j]+;
end[i]=end[j];
next[i]=next[j];
}
else
{
next[i]=j;
end[i]=i;
cnt[i]=;
}
}
}
void solve(int x)
{
int c=cnt[x],e=end[x];
while()
{
x=next[x];
if(x>n)
break;
c+=cnt[x];
e=end[x];
}
printf("%d %d\n",e,c);
}
int main()
{
n=read(),m=read();
block=ceil(sqrt(n*1.0));
for(int i=;i<=n;i++)
power[i]=read();
for(int i=n;i>=;i--)
update(i,i+power[i]);
for(int i=;i<m;i++)
{
int q=read();
if(q)
{
int v=read();
solve(v);
}
else
{
int a=read(),b=read();
update(a,a+b);
for(int i=a-;i>=a/block*block;i--)
update(i,i+power[i]);
power[a]=b;
}
}
}

Codeforces Beta Round #13 E. Holes 分块暴力的更多相关文章

  1. Codeforces Beta Round #13 E. Holes (分块)

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

  2. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  3. Codeforces Beta Round #17 A - Noldbach problem 暴力

    A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...

  4. Codeforces Beta Round #37 B. Computer Game 暴力 贪心

    B. Computer Game 题目连接: http://www.codeforces.com/contest/37/problem/B Description Vasya's elder brot ...

  5. Codeforces Beta Round #10 B. Cinema Cashier 暴力

    B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...

  6. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

    题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...

  7. 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

    题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

随机推荐

  1. 继承TextView简单画一个尺子

    import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; impor ...

  2. ajax轮询

    oa.comet = function (id) {    if (oa.id == 0) oa.id = id;    $.ajax({        url: '/comet.asy?id=' + ...

  3. lua Date和Time

    time和date两个函数在Lua中实现所有的时钟查询功能.函数time在没有参数时返回当前时钟的数值.(在许多系统中该数值是当前距离某个特定时间的秒数.)当为函数调用附加一个特殊的时间表时,该函数就 ...

  4. [翻译]Python——十年语言之冠

    最近我发现了这个PYPL——编程语言流行指数.它对各种语言的流行指标进行了二次发掘.作者指出TIOBE指数很可能不能反映出真实情况,归咎于一些编程语言的名称会导致误解.他引入了一些新术语,利用谷歌趋势 ...

  5. 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码

    JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...

  6. 转-问自己:UI设计注意的十个问题

    UI 设计需要自问的 10个问题   UI 设计的魅力在于,你不仅需要适当的技巧,更要理解用户与程序的关系.一个有效的用户界面关注的是用户目标的实现,包括视觉元素与功能操作在内的所有东西都需要完整一致 ...

  7. oracle 体系结构解析

    三.oracle 体系结构 1.oracle内存由SGA+PGA所构成 2.oracle数据库体系结构数据库的体系结构是指数据库的组成.工作过程与原理,以及数据在数据库中的组织与管理机制. oracl ...

  8. Failed to read artifact descriptor--maven问题总结(能力工场)

    在开发的过程中,作为新手,经常遇到Maven下载依赖的时候,"Failed to read artifact descriptor for xxx:jar"的错误 对于这种非业务相 ...

  9. Android内存管理之道

    相信一步步走过来的Android从业者,每个人都会遇到OOM的情况.如何避免和防范OOM的出现,对于每一个程序员来说确实是一门必不可少的能力.今天我们就谈谈在Android平台下内存的管理之道,开始今 ...

  10. Cisco SDM

    SDM连接方式:http+telnet / https+ssh   要使用SDM对CISCO设备实现集中式管理,必须在设备上键入如下命令:   步骤1: 要启用路由器的HTTP/HTTPS 服务器,请 ...