Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5 + 50;
- const int L = 500;
- int dp[N];
- int link[N];
- int l[N], r[N];
- int a[N];
- int n, m;
- void build(int num) {
- int f = min(n - 1, r[num]);
- for (int i = f; i >= l[num]; --i) {
- int nxt = a[i] + i;
- if (nxt > f) {
- dp[i] = 1;
- link[i] = i;
- }
- else {
- dp[i] = dp[nxt] + 1;
- link[i] = link[nxt];
- }
- }
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- l[0] = 0;
- r[0] = L - 1;
- for (int i = 1; i < N; ++i) {
- l[i] = r[i - 1] + 1;
- r[i] = l[i] + L - 1;
- }
- cin >> n >> m;
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- for (int i = 0; l[i] < n; ++i) {
- build(i);
- }
- for (int i = 0; i < m; ++i) {
- int t, pos, elem;
- cin >> t >> pos;
- pos--;
- if (t == 0) {
- cin >> elem;
- a[pos] = elem;
- build(pos / L);
- }
- else {
- int res = 0, lst = -1;
- while (pos < n) {
- lst = link[pos];
- res += dp[pos];
- pos = link[pos] + a[link[pos]];
- }
- cout << lst + 1 << " " << res << "\n";
- }
- }
- return 0;
- }
- /*
- * int overflow, array bounds
- * special cases (n=1?), set tle
- * do smth instead of nothing and stay organized
- * double troubles
- * same points in geoma
- * in game theory find win cases
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement