Pagini recente » Cod sursa (job #804428) | Cod sursa (job #2136549) | Cod sursa (job #1709487) | Cod sursa (job #1026881) | Cod sursa (job #3197952)
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
const int nMax=15001;
int t[nMax],n;
void update(int poz,int val){
while(poz<=n){
t[poz]+=val;
poz+=poz&(-poz);
}
}
int query(int poz){
int rez;
rez=0;
while(poz>=1){
rez+=t[poz];
poz&=(poz-1);
}
return rez;
}
int main(){
int m;
f>>n>>m;
for(int i=1;i<=n;++i){
int x;
f>>x;
update(i,x);
}
for(int i=1;i<=m;++i){
int cer,x,y;
f>>cer>>x>>y;
if(cer)
g<<query(y)-query(x-1)<<'\n';
else update(x,-y);
}
return 0;
}