Pagini recente » Borderou de evaluare (job #1537082) | Cod sursa (job #429196) | Cod sursa (job #51464) | Cod sursa (job #3325544) | Cod sursa (job #3337754)
#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
int n;
vector<long long> f;
Fenwick(int n) : n(n), f(n+1,0) {}
void update(int i,long long v){
for(;i<=n;i+=i&-i) f[i]+=v;
}
long long query(int i){
long long s=0;
for(;i>0;i-=i&-i) s+=f[i];
return s;
}
long long range(int l,int r){
return query(r)-query(l-1);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
int N,M;
cin>>N>>M;
Fenwick fenw(N);
vector<int>A(N+1);
for(int i=1;i<=N;i++){
cin>>A[i];
fenw.update(i,A[i]);
}
for(int i=0;i<M;i++){
int c,x,y;
cin>>c>>x>>y;
if(c==0){
fenw.update(x,-y);
}else{
cout<<fenw.range(x,y)<<"\n";
}
}
}