提交时间:2022-11-03 09:32:29
运行 ID: 63981
#include <bits/stdc++.h> using namespace std; const int MXN = 200005; int N, BW, M, stp[MXN]; int jumpto[MXN], jumpln[MXN]; void updt(int b) { if (b >= N / BW) return; for (int i(b * BW + BW - 1); i >= b * BW; --i) { jumpto[i] = i + stp[i]; jumpln[i] = 1; if (jumpto[i] / BW == b) jumpln[i] += jumpln[jumpto[i]], jumpto[i] = jumpto[jumpto[i]]; } } int jump(int p) { int s(0); while (p < N) { s += jumpln[p]; p = jumpto[p]; } return s; } int main() { cin >> N; BW = sqrt(N); for (int i(0); i != N; ++i) cin >> stp[i], stp[i] = min(stp[i], N - i), jumpln[i] = 1, jumpto[i] = i + stp[i]; for (int i(N / BW - 1); ~i; --i) updt(i); cin >> M; for (int i(0), j(0); M--;) { cin >> i >> j; if (i == 1) { cout << jump(j) << endl; } else { int k(0); cin >> k; stp[j] = min(k, N - j); updt(j / BW); } } return 0; }