Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
63981 | _ | [Hnoi2010]Bounce 弹飞绵羊 | C++ | 通过 | 100 | 490 MS | 2588 KB | 975 | 2022-11-03 09:32:29 |
#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; }