-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
70 lines (63 loc) · 1.25 KB
/
Copy pathE.cpp
File metadata and controls
70 lines (63 loc) · 1.25 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
#define cerr cerr << "DEBUG "
template <typename T> inline int len(const T &a) { return (int) a.size(); }
constexpr int N = 1e5 + 10, SQ = 350;
int n, m;
int a[N], dp[N], cnt[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
dp[i] = i;
int num = i / SQ;
int lm = min(n, (num + 1) * SQ);
while (dp[i] + a[dp[i]] < lm) {
dp[i] += a[dp[i]];
++cnt[i];
}
}
while (m--) {
int op;
cin >> op;
if (op == 0) {
int i, x;
cin >> i >> x;
--i;
a[i] = x;
int num = i / SQ;
int lm = min(n, (num + 1) * SQ);
for (int j = lm - 1; j >= num * SQ; --j) {
dp[j] = j;
cnt[j] = 0;
if (j + a[j] < lm) {
dp[j] = dp[j + a[j]];
cnt[j] = cnt[j + a[j]] + 1;
}
}
} else {
int i;
cin >> i;
--i;
int sum = 0;
//cerr << i << '\n';
while (true) {
sum += cnt[i];
i = dp[i];
//cerr << i << '\n';
if (i + a[i] >= n) {
break;
}
i += a[i];
//cerr << i << '\n';
sum++;
}
//cerr << '\n';
cout << i + 1 << ' ' << sum + 1 << '\n';
}
}
}