题目链接:

E. Holes

time limit per test

1 second

memory limit per test

64 megabytes

input

standard input

output

standard output

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:

  • a b
  • 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.

Examples
input
8 5
1 1 1 1 1 2 8 2
1 1
0 1 3
1 1
0 3 4
1 2
output
8 7
8 5
7 3 题意:从第i个洞可以到达i+power[i],0操作:power[x]=y,1操作询问从x跳出去一共跳了多少步,最后一个洞的编号;
思路:nex[i],num[i],last[i]表示从第i个洞跳到下一个块的洞的标号、跳的数目、和在次块的最后的洞的编号;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,power[maxn],nex[maxn],num[maxn],sq,last[maxn];
inline void init()
{
sq=sqrt(n*1.0);
for(int i=n;i>0;i--)
{
int ne=i+power[i];
if(ne>n)num[i]=1,nex[i]=ne,last[i]=i;
else
{
if(ne/sq==i/sq)num[i]=num[ne]+1,nex[i]=nex[ne],last[i]=last[ne];
else num[i]=1,nex[i]=ne,last[i]=i;
}
}
}
inline void update(int x,int y)
{
power[x]=y;
for(int i=x;i>0&&i/sq==x/sq;i--)
{
int ne=i+power[i];
if(ne>n)num[i]=1,nex[i]=ne,last[i]=i;
else
{
if(ne/sq==i/sq)num[i]=num[ne]+1,nex[i]=nex[ne],last[i]=last[ne];
else num[i]=1,nex[i]=ne,last[i]=i;
}
}
}
inline void query(int x)
{
int p=x,ans=0,la=last[x];
while(p<=n)
{
ans+=num[p];
la=last[p];
p=nex[p];
}
printf("%d %d\n",la,ans);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&power[i]);
init();
while(m--)
{
int op,x,y;
scanf("%d",&op);
if(op)scanf("%d",&x),query(x);
else scanf("%d%d",&x,&y),update(x,y);
}
return 0;
}

  

E. Holes(分块)的更多相关文章

  1. Codeforces Beta Round #13 E. Holes 分块暴力

    E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...

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

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

  3. CF 13E. Holes 分块数组

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

  4. CodeForces 13E. Holes 分块处理

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

  5. codeforces 13E . Holes 分块

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

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

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

  7. (分块)Holes CodeForces - 13E

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

  8. CF13E Holes LCT

    CF13E Holes LG传送门 双倍经验题,几乎同[HNOI2010]弹飞绵羊,LCT练手题,LG没有LCT题解于是发一波. 从当前点向目标点连边,构成一棵树,带修改就用LCT动态维护答案,由于不 ...

  9. CF 13E Holes

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

随机推荐

  1. 20145331 《Java程序设计》第2周学习总结

    20145331<Java程序设计>第2周学习总结 教材学习内容总结 3.1 类型.变量与运算符 •注释://(单行注释).//(多行注释)./ */(javadoc文档注释 )注释的内容 ...

  2. Mysql 默认编码问题

    新安装的数据库默认编码是 latin1 +--------------------------+----------------------------+ | Variable_name | Valu ...

  3. visual studio中添加existing web site, website名字附带数字

    用visual studio直接运行website项目 发现有一个conifg文件的配置,路径是solution同级目录下的.vs/config文件夹下有一个applicationhost.confi ...

  4. 洛谷 P2015 二叉苹果树(codevs5565) 树形dp入门

    dp这一方面的题我都不是很会,所以来练(xue)习(xi),大概把这题弄懂了. 树形dp就是在原本线性上dp改成了在 '树' 这个数据结构上dp. 一般来说,树形dp利用dfs在回溯时进行更新,使用儿 ...

  5. 爬虫之Xpath案例

    案例:使用XPath的爬虫 现在我们用XPath来做一个简单的爬虫,我们尝试爬取某个贴吧里的所有帖子,并且将该这个帖子里每个楼层发布的图片下载到本地. # tieba_xpath.py #!/usr/ ...

  6. 上采样和PixelShuffle(转)

    有些地方还没看懂, mark一下 文章来源: https://blog.csdn.net/g11d111/article/details/82855946 去年曾经使用过FCN(全卷积神经网络)及其派 ...

  7. spring boot2.1读取 apollo 配置中心1

    第一篇:搭建apollo配置中心 为什么选择apollo,我做了一些对比:   Diamond Disconf Apollo Spring Cloud Config 数据持久性 mysql mysql ...

  8. sql数据类型转换函数

    1.CAST()CAST (<expression> AS <data_ type>[ length ]) 2.CONVERT()CONVERT (<data_ type ...

  9. CSS布局框架 960GS

    1.960GS 特点 小巧简单,功能单一(仅仅做排版的工作,其他东西靠自己.)(三个文件:reset.css,960.css,font.css) 界面宽960px,适合目前主流1/2以上显示器都满屏宽 ...

  10. weblogic 12c重置console密码

    su - oracle cd /u02/weblogic/user_projects/domains/base_domain source   bin/setDomainEnv.sh cd /u02/ ...