Pagini recente » Cod sursa (job #142068) | Cod sursa (job #2487988) | Cod sursa (job #2740329) | Cod sursa (job #223047) | Cod sursa (job #2908048)
#include <bits/stdc++.h>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
#define cin in
#define cout out
#define NMAX 15005
int s[NMAX], n, m;
void update(int pos, int val) {
while (pos <= n) {
s[pos] += val;
pos += pos & -pos;
}
}
int query(int pos) {
int sum = 0;
while (pos) {
sum += s[pos];
pos -= pos & -pos;
}
return sum;
}
void range_query(int l, int r) {
cout << query(r) - query(l - 1) << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
update(i, x);
}
for (int i = 1; i <= m; i++) {
int cmd, x, y;
cin >> cmd >> x >> y;
if (cmd)
range_query(x, y);
else
update(x, -y);
}
return 0;
}