代码过不去
查看原帖
代码过不去
420129
Nt_Tsumiki楼主2021/7/21 09:32

题解和我的都过不去

代码:

#include <iostream>

using namespace std;
int n,m;
int c[1000001];

int lowbit(int x) {
    return x&(-x);
}

void updata(int x,int k) {
    while (x<=n) {
        c[x]+=k;
        x+=lowbit(x);
    }
}

int getsum(int x) {
    int ans=0;
    while (x>0) {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}

int main() {
    cin>>n>>m;
    for (int i=1;i<=m;i++) {
        char s;
        int x,y;
        cin>>s>>x>>y;
        if (s=='x') {
            updata(x,y);
        } else if (s=='y') {
            cout<<getsum(y)-getsum(x-1)<<endl;
        }
    }
}
2021/7/21 09:32
加载中...