1 条题解

  • 0
    @ 2023-4-27 21:04:30
    #include<bits/stdc++.h>
    using namespace std;
    const int Maxn=500010;
    int m=32010;
    long long int c[Maxn];
    int n,k;
    int lowbit(int x){
        return x&(-x);
    }
    void Update(int x,int k){
        for(; x<=m; x+=lowbit(x)){
            c[x]+=k;
        }
    }
    int Sum(int x){
        int res=0;
        for(; x; x-=lowbit(x)){
            res+=c[x];
        }
        return res;
    }
    int main()
    {
        cin>>n>>k;
        char opt;
        int p,h;
        for(int i=1;i<=k;i++)
        {
            cin>>opt;
            if(opt=='A'){
                cin>>p;
                cout<<Sum(p)<<endl;
            }
            if(opt=='B'){
                cin>>p>>h;
                Update(p,h);
            }
            if(opt=='C'){
                cin>>p>>h;
                Update(p,-h);
            }
               
    
        }
        
    }
    

    呐呐呐

    • 1

    「一本通 4.1 练习 1」清点人数

    信息

    ID
    595
    时间
    200ms
    内存
    512MiB
    难度
    6
    标签
    递交数
    24
    已通过
    11
    上传者