forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
13E.go
56 lines (51 loc) · 937 Bytes
/
13E.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"bufio"
. "fmt"
"io"
)
// https://space.bilibili.com/206214
func CF13E(_r io.Reader, _w io.Writer) {
in := bufio.NewReader(_r)
out := bufio.NewWriter(_w)
defer out.Flush()
var n, q, op, p, v, last int32
Fscan(in, &n, &q)
a := make([]int32, n)
for i := range a {
Fscan(in, &a[i])
}
const B = 500
type pair struct{ last, jump int32 }
data := make([]pair, n)
f := func(i int32) {
if i+a[i] >= n || i/B != (i+a[i])/B {
data[i] = pair{i, 0}
} else {
data[i] = data[i+a[i]]
data[i].jump++
}
}
for i := n - 1; i >= 0; i-- {
f(i)
}
for ; q > 0; q-- {
Fscan(in, &op, &p)
p--
if op == 0 {
Fscan(in, &v)
a[p] = v
for i := p; i >= p-p%B; i-- {
f(i)
}
} else {
jump := int32(0)
for ; p < n; p = last + a[last] {
jump += data[p].jump + 1
last = data[p].last
}
Fprintln(out, last+1, jump)
}
}
}
//func main() { CF13E(os.Stdin, os.Stdout) }