Pagini recente » Cod sursa (job #159894) | Cod sursa (job #301238) | Cod sursa (job #3229918) | Cod sursa (job #636387) | Cod sursa (job #1606019)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int NMAX = 15000;
const int MMAX = 100000;
typedef long long in64;
int n; int m;
in64 aib[NMAX + 1];
int nextBit(int x) {
return x & (-x);
}
void update(int pos, in64 val) {
while(pos <= n) {
aib[pos] += val;
pos += nextBit(pos);
}
}
in64 query(int pos) {
in64 sum = 0;
while(pos) {
sum += aib[pos];
pos -= nextBit(pos);
}
return sum;
}
int main() {
fin >> n >> m;
for(int i = 1; i <= n; ++i) {
int val; fin >> val;
update(i, val);
}
while(m--) {
int type; int x; int y;
fin >> type >> x >> y;
if(type == 0) update(x, -y);
if(type == 1) fout << query(y) - query(x - 1) << '\n';
}
return 0;
}