Pagini recente » Borderou de evaluare (job #462452) | Borderou de evaluare (job #477352) | Autentificare | Cod sursa (job #1458596) | Cod sursa (job #3350000)
#include <bits/stdc++.h>
#define MAXN 15000
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int aib[MAXN + 1], n;
int lsb(int x){
return x & (-x);
}
void update(int pos, int val){
while(pos <= n){
aib[pos] += val;
pos += lsb(pos);
}
}
int preff(int pos){
int rez = 0;
while(pos){
rez += aib[pos];
pos -= lsb(pos);
}
return rez;
}
int query(int x, int y){
return preff(y) - preff(x - 1);
}
int main()
{
int m, i, t, x, y;
fin >> n >> m;
for(i = 1; i <= n; i++){
fin >> x;
update(i, x);
}
while(m--){
fin >> t >> x >> y;
if(t == 0){
update(x, -y);
}else{
fout << query(x, y) << "\n";
}
}
return 0;
}