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.

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
分块,对每次更新,维护每个块里面的每个元素的三个属性:下一个到达的位置,跳的次数,最后一次跳的位置。
 #include <cstdio>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> #define lid id<<1
#define rid id<<1|1
#define closein cin.tie(0)
#define scac(a) scanf("%c",&a)
#define scad(a) scanf("%d",&a)
#define print(a) printf("%d\n",a)
#define debug printf("hello world")
#define form(i,n,m) for(int i=n;i<m;i++)
#define mfor(i,n,m) for(int i=n;i>m;i--)
#define nfor(i,n,m) for(int i=n;i>=m;i--)
#define forn(i,n,m) for(int i=n;i<=m;i++)
#define scadd(a,b) scanf("%d%d",&a,&b)
#define memset0(a) memset(a,0,sizeof(a))
#define scaddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scadddd(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) #define INF 0x3f3f3f3f
#define maxn 100005
typedef long long ll;
using namespace std;
//---------AC(^-^)AC---------\\ int n,m,blo;
int cnt[maxn],nxt[maxn],last[maxn],power[maxn]; void update(int i,int j)
{
if(j>n)
{
cnt[i]=;
last[i]=i;
nxt[i]=n+;
}
else if(i/blo==j/blo)
{
nxt[i]=nxt[j];
cnt[i]=cnt[j]+;
last[i]=last[j];
}
else
{
nxt[i]=j;
last[i]=i;
cnt[i]=;
}
}
void query(int x)
{
int num,ans;
ans=cnt[x];
num=last[x];
while(true)
{
x=nxt[x];
if(x>n) break;
num=last[x];
ans+=cnt[x];
}
printf("%d %d\n",num,ans);
} int main()
{
scadd(n,m);
blo=ceil(sqrt(n));
forn(i,,n) scad(power[i]);
nfor(i,n,) update(i,i+power[i]);
while(m--)
{
int op;
scad(op);
if(op==)
{
int x;
scad(x);
query(x);
}
else
{
int x,y;
scadd(x,y);
power[x]=y;
for(int i=x;i&&i/blo==x/blo;i--) update(i,i+power[i]); }
}
return ;
}

<-click here to see the code

CodeForces - 13E的更多相关文章

  1. CodeForces 13E 分块

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

  2. codeforces 13E . Holes 分块

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

  3. CodeForces 13E. Holes 分块处理

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

  4. (分块)Holes CodeForces - 13E

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

  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. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. (转载)Unity 关于动态监听时,点击Button,返回其在数组中的下标

    其实是绕了一圈,把数组里的元素放进数组列表里再读取它的下标 using System.Collections; using System.Collections.Generic; using Unit ...

  2. 1_Linux概述

    linux就是一套操作系统 //系统调用与内核如果能够参考硬件的功能函数并修改你的操作系统程序代码,那经过改版后的操作系统就能够在另一个硬件平台上面运行了,这个操作通常被称为"软件移植&qu ...

  3. 微信小程序之 真机键盘弹窗遮盖input框

    正常效果: 问题效果: 发现这个问题后呢,我先去看了api,api上是这么说的 哦吼~ 然后我也不知道是不是我的打开方式不对还是什么~~ 没有效果~~  那怎么办呢~~  换方法呗~~ 我只好用这个方 ...

  4. Unity3D外包(u3d外包)—就找北京动点软件(我们长年承接U3D外包、Maya、3DMax项目外包)

    一.关于动点: 北京动点飞扬软件,因致力于虚拟现实技术的开发而创立,在虚拟现实开发领域有着卓越的技术和领先的思想.   我们为用户专业定制的项目,细分了多种工作流程,软件独立自主研发,编程简化用户操作 ...

  5. redhat7.2安全基线BI

    (一)   Redhat linux7.2安全基线基本型(BI) 1.   密码复杂度策略 /etc/pam.d/system-auth文件中,增加内容 password requisite pam_ ...

  6. JS打开新窗口防止被浏览器阻止的方法

    这篇文章主要介绍了JS打开新窗口防止被浏览器阻止的方法,分析对比了常用方法与改进方法,是非常实用的技巧,需要的朋友可以参考下 本文实例讲述了JS打开新窗口防止被浏览器阻止的方法.分享给大家供大家参考. ...

  7. English trip EM2-PE-5A Plan a dinner party Teacher:Lamb

    课上内容(Lesson) # Appetizer   ['æpə'taɪzɚ]  n. 开胃物,开胃食品 spinach salad  菠菜沙拉  # "p" 发b音 gazpac ...

  8. linux存储管理之文件系统

    EXT3/4文件系统 ====================================================================================Ext3: ...

  9. dilated convolutions:扩张卷积

    最近在阅读<Context Encoding for Semantic Segmentation>中看到应用了dilated convolutions. 扩张卷积与普通的卷积相比,除了卷积 ...

  10. ILMerge合并多个DLL (转)

    最近在研究CodeDom,用到ILMerge 序言 如果你的项目要提供多个dll给别人用,那么不妨让你的dll合并为一个,让别人看起来简洁,引用起来不会过于繁琐. 本篇比较少,但也算是比较实用吧. 下 ...