Pagini recente » Cod sursa (job #1752957) | Cod sursa (job #1225967) | Cod sursa (job #2662451) | Cod sursa (job #2604885) | Cod sursa (job #2570762)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
const int maxn = 100005;
int n, m;
int arb[maxn << 2];
inline void update(int poz, int value){
while(poz <= n){
arb[poz] += value;
int lsb = poz & (-poz);
poz += lsb;
}
}
int query(int poz){
int ans = 0;
while(poz){
ans += arb[poz];
int lsb = poz & (-poz);
poz -= lsb;
}
return ans;
}
int main(){
in >> n >> m;
for(int i = 1; i <= n; ++i){
int x;
in >> x;
update(i, x);
}
while(m--){
int op, a, b;
in >> op >> a >> b;
if(!op)
update(a, -b);
else
out << query(b) - query(a-1) << '\n';
}
return 0;
}