Pagini recente » Cod sursa (job #2436271) | Cod sursa (job #1619186) | Cod sursa (job #1701071) | Cod sursa (job #2886296) | Cod sursa (job #2792049)
#include <fstream>
#define NMAX 15000
using namespace std;
ifstream cin ("datorii.in");
ofstream cout ("datorii.out");
int n;
int vaib[NMAX + 1];
static inline int lsb(int val) {
return val & (- val);
}
void update(int poz, int val) {
while (poz <= n) {
vaib[poz] += val;
poz += lsb(poz);
}
}
int query(int poz) { /// return the sum of [1, n]
int sol = 0;
while (poz > 0) {
sol += vaib[poz];
poz -= lsb(poz);
}
return sol;
}
int main() {
int t, i, val, op, x, y;
cin >> n >> t;
for (i = 1; i <= n; i++) {
cin >> val;
update(i, val);
}
while (t--) {
cin >> op >> x >> y;
if (op == 0)
update(x, -y);
else
cout << query(y) - query(x - 1) << "\n";
}
return 0;
}