PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000011. Những chiếc hố (Holes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những chiếc hố (Holes)

Holes

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn holes in a row, indexed from 11 to nn. Hole ii has a positive power aia_i. A ball dropped at hole pp immediately jumps to p+app+a_p. If the destination is still in the row, the same rule is applied again. Once the next position is greater than nn, the ball leaves the row.

Process mm operations in input order:

  • 0 a b: Assign the power of hole aa to bb, replacing its previous value.
  • 1 a: Drop a ball into hole aa and report the last hole visited before leaving the row and the total number of jumps, including the final jump out of the row.

Since every power is positive, the ball always moves right and eventually exits. Ball-dropping queries do not modify the powers.

Input

The first line contains n,mn,m. The second line contains a1,…,ana_1,\ldots,a_n. Each of the next mm lines is either 0 a b or 1 a.

Output

For each type-1 operation, print last jumps on a separate line: the final in-row hole and the number of jumps.

Subtasks

  • Subtask 1 (15 points): 1≤n≤501\le n\le 50; 1≤m≤601\le m\le 60; 1≤ai≤n1\le a_i\le n; trong lệnh 0 a b, 1≤a,b≤n1\le a,b\le n; trong lệnh 1 a, 1≤a≤n1\le a\le n.
  • Subtask 2 (20 points): 1≤n≤25001\le n\le 2500; 1≤m≤30001\le m\le 3000; 1≤ai≤n1\le a_i\le n; trong lệnh 0 a b, 1≤a,b≤n1\le a,b\le n; trong lệnh 1 a, 1≤a≤n1\le a\le n.
  • Subtask 3 (25 points): 1≤n≤200001\le n\le 20000; 1≤m≤200001\le m\le 20000; 1≤ai≤n1\le a_i\le n; trong lệnh 0 a b, 1≤a,b≤n1\le a,b\le n; trong lệnh 1 a, 1≤a≤n1\le a\le n.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le 100000; 1≤m≤1000001\le m\le 100000; 1≤ai≤n1\le a_i\le n; trong lệnh 0 a b, 1≤a,b≤n1\le a,b\le n; trong lệnh 1 a, 1≤a≤n1\le a\le n.

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

Explanation

Initially the visited holes from 11 are 1,2,3,4,5,6,81,2,3,4,5,6,8, followed by the exit: last hole 88, 77 jumps. After 0 1 3, the path is 1,4,5,6,81,4,5,6,8: 55 jumps. After 0 3 4, starting at 22 visits 2,3,72,3,7 and exits after 33 jumps.