这个屑哪里爆了?
查看原帖
这个屑哪里爆了?
152053
jiunianqing楼主2022/6/18 18:15
#include<bits/stdc++.h>
using namespace std;
const int N=100009;
inline int read(){
    int x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+c-48;c=getchar();}
    return x*f;
}
long long n,w;
int c[N];
void add(int x,int k){
    for(;x<=n;x+=x&-x){
        c[x]+=k;
    }
}
long long query(int x){
    long long sum=0;
    for(;x;x-=x&-x){
        sum+=c[x];
    }
    return sum;
}
int main(){
    n=read();w=read();
    for(int i=1;i<=w;i++){
        char op;
        long long p,q;
        cin>>op;
        p=read();q=read();
        if(op=='x'){
            add(p,q);
        }
        if(op=='y'){
            cout<<query(q)-query(p-1)<<endl;
        }
    }
    return 0;
}

QAQ

2022/6/18 18:15
加载中...