CF13E.Holes

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:64MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 a__i). If you throw a ball into hole i it will immediately jump to hole i + a__i, 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.

小佩佳很喜欢玩游戏,尤其喜欢玩“洞穴”游戏。这是一个单人游戏,规则如下:

有 NN 个洞穴排成一行,从左到右依次编号为 11 到 NN。每个洞穴都有其对应的“力量”(洞穴 ii 的力量为 aia_i)。若将一个小球投入洞穴 ii,它会立即跳至洞穴 i+aii + a_i,然后继续从该洞穴跳出,依此类推。若目标位置不存在对应编号的洞穴,则小球直接跳出整行。

在总共 MM 次操作中,玩家每次可执行以下两种操作之一:

  • 将洞穴 aa 的力量设为 bb;
  • 将一个小球投入洞穴 aa,统计小球在跳出整行前共跳跃了多少次,并记录小球跳出整行前最后所在的洞穴编号。

佩佳不擅长数学运算,因此——正如你已猜到的那样——所有计算都由你来完成。

输入格式

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.

第一行包含两个整数 NN 和 MM(1≤N≤1051 \leq N \leq 10^5,1≤M≤1051 \leq M \leq 10^5)—— 分别表示一行中洞的数量和操作次数。
第二行包含 NN 个不超过 NN 的正整数——表示各洞的初始能量值。
接下来的 MM 行描述了 Petya 所做的操作。每行属于以下两种类型之一:

  • 0 a b
  • 1 a

类型 0 表示将第 aa 个洞的能量值设置为 bb;类型 1 表示向第 aa 个洞中投掷一个球。其中 aa 和 bb 均为不超过 NN 的正整数。

输出格式

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.

对于每种类型 1 的移动,在单独一行上输出两个以空格分隔的数字——球在离开该行前最后经过的洞的编号,以及它所进行的跳跃次数。

输入输出样例

  • 输入#1

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

    输出#1

    8 7
    8 5
    7 3

输入解题思路,AI测评打分。不知道怎么写?

首页