比赛 |
2025.3.6 |
评测结果 |
AAAAAAAAAA |
题目名称 |
弹飞绵羊 |
最终得分 |
100 |
用户昵称 |
wdsjl |
运行时间 |
3.804 s |
代码语言 |
C++ |
内存使用 |
9.73 MiB |
提交时间 |
2025-03-06 20:05:08 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 200010;
vector<int> k(MAXN);
int block;
vector<int> bl(MAXN);
vector<int> l(MAXN >> 1);
vector<int> f(MAXN);
vector<int> to(MAXN);
int n, m;
void replace(int p, int w) {
k[p] = w;
for (int i = l[bl[p] + 1] - 1; i >= l[bl[p]]; --i) {
if (i + k[i] >= l[bl[i] + 1]) {
f[i] = 1;
to[i] = i + k[i];
} else {
f[i] = f[i + k[i]] + 1;
to[i] = to[i + k[i]];
}
}
}
int query(int p) {
int result = 0;
while (p <= n) {
result += f[p];
p = to[p];
}
return result;
}
signed main() {
freopen("bzoj_2002.in","r",stdin);
freopen("bzoj_2002.out","w",stdout);
scanf("%lld",&n);
block = static_cast<int>(sqrt(n));
for (int i = 1; i <= n; ++i) {
scanf("%lld",&k[i]);
bl[i] = (i - 1) / block + 1;
if (bl[i] != bl[i - 1]) {
l[bl[i]] = i;
}
}
l[bl[n] + 1] = n + 1;
for (int i = n; i >= 1; --i) {
if (i + k[i] >= l[bl[i] + 1]) {
f[i] = 1;
to[i] = i + k[i];
} else {
f[i] = f[i + k[i]] + 1;
to[i] = to[i + k[i]];
}
}
scanf("%lld",&m);
int op, p, w;
while (m--) {
scanf("%lld",&op);
scanf("%lld",&p);
if (op == 1) {
cout << query(p + 1) << endl;
} else {
scanf("%lld",&w);
replace(p + 1, w);
}
}
return 0;
}