70分 re 求调
查看原帖
70分 re 求调
786844
wang126179楼主2022/11/27 23:35
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a,b,m,c;
ll tr[200005]={0};
inline int lowbit(int x){
    return x & -x;
}
void add(int x, int c){
    for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;
}
int sum(int x){
    int res = 0;
    for (int i = x; i>0; i -= lowbit(i)) res += tr[i];
    return res;
}
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a;
        add(i,a);
    }
    for(int i=1;i<=m;i++){
        cin>>b>>a>>c;
        if(b==1){
            add(a,c);
        }else{
            cout<<sum(c)-sum(a-1)<<"\n";
        }
    }
    return 0;
}
2022/11/27 23:35
加载中...