比赛 2025.3.6 评测结果 AAAAAAAAAA
题目名称 弹飞绵羊 最终得分 100
用户昵称 darkMoon 运行时间 1.841 s
代码语言 C++ 内存使用 6.13 MiB
提交时间 2025-03-06 19:25:21
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
auto IN = freopen("bzoj_2002.in", "r", stdin);
auto OUT = freopen("bzoj_2002.out", "w", stdout);
auto IOS = ios::sync_with_stdio(false);
auto CIN = cin.tie(nullptr);
int mread(){
    int x = 0, f = 1;
    char c = cin.get();
    while(c < '0' || c > '9'){
        if(c == '-'){
            f = -1;
        }
        c = cin.get();
    }
    while(c >= '0' && c <= '9'){
        x = x * 10 + c - '0';
        c = cin.get();
    }
    return x * f;
}
const int N = 2e5 + 5;
int n = mread(), a[N], l[N], r[N], belong[N], b, nxt[N], len[N];
void build(int x){
    for(int i = r[x]; i >= l[x]; i --){
        if(i + a[i] > r[x]){
            nxt[i] = i + a[i];
            len[i] = 1;
        }
        else{
            len[i] = len[i + a[i]] + 1;
            nxt[i] = nxt[i + a[i]];
        }
    }
    return;
}
int query(int x){
    int ans = 0;
    while(x <= n){
        ans += len[x];
        x = nxt[x];
    }
    return ans;
}
signed main(){
    b = sqrt(n);
    for(int i = 1; i <= n; i ++){
        a[i] = mread();
    }
    for(int i = 1; i <= b; i ++){
        l[i] = r[i - 1] + 1;
        r[i] = l[i] + b - 1;
    }
    r[b] = n;
    for(int i = 1; i <= b; i ++){
        for(int j = l[i]; j <= r[i]; j ++){
            belong[j] = i;
        }
    }
    for(int i = 1; i <= b; i ++){
        build(i);
    }
    int q = mread();
    while(q --){
        int op = mread();
        if(op == 1){
            int x = mread() + 1;
            cout << query(x) << "\n";
        }
        else{
            int p = mread() + 1, k = mread();
            a[p] = k;
            build(belong[p]);
        }
    }
    return 0;
}