Pagini recente » Cod sursa (job #3271025) | Cod sursa (job #1385827) | Cod sursa (job #2492887) | Cod sursa (job #2919730) | Cod sursa (job #2288724)
#include<bits/stdc++.h>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int n,q,a[16000],t[16000];
int query(int k){
int res=0;
for(int i=k; i>0; i-=(i&-i))
res+=t[i];
return res;
}
void create(int k, int x){
for(int i=k; i<=n; i+=(i&-i))
t[i]+=x;
}
void update(int k, int x){
for(int i=k; i<=n; i+=(i&-i))
t[i]-=x;
}
int main(){
in >> n >> q;
for(int i=1; i<=n; i++){
in >> a[i];
create(i,a[i]);
}
for(int i=1; i<=q; i++){
int type,x,y;
in >> type >> x >> y;
if(type==0) update(x,y);
else out << query(y)-query(x-1) << "\n";
}
return 0;
}