Pagini recente » Cod sursa (job #1021573) | Cod sursa (job #2361026) | Cod sursa (job #2101401) | Cod sursa (job #1422503) | Cod sursa (job #3040111)
/// [A][M][C][B][N] ///
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int nmax = 15e3;
int n, m;
int v[nmax + 1]{ 0 };
int t[nmax + 1]{ 0 };
void update(int i, int x) {
for (; i <= n; i += i & -i) {
t[i] += x;
}
}
int query(int i) {
int s = 0;
for (; i > 0; i -= i & -i) {
s += t[i];
}
return s;
}
int query(int i, int j) {
return query(j) - query(i - 1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
fin >> v[i];
update(i, v[i]);
}
while (m--) {
int c, p, q;
fin >> c >> p >> q;
if (c) {
fout << query(p, q) << '\n';
}
else {
update(p, -q);
}
}
}