Pagini recente » Cod sursa (job #3364231) | Cod sursa (job #3364086) | Cod sursa (job #3364016) | Cod sursa (job #2351755) | Cod sursa (job #3364018)
#include <bits/stdc++.h>
using namespace std;
struct BIT {
vector<int> aib;
BIT(int n) {
aib.resize(n + 1);
}
int query(int i) {
int ans = 0;
for (; i > 0; i -= i & (-i)) {
ans += aib[i];
}
return ans;
}
void update(int i, int x) {
for (; i < int(aib.size()); i += i & (-i)) {
aib[i] += x;
}
}
};
signed main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
#endif
int n, m; cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
BIT aib(n + 1);
for (int i = 1; i <= n; ++i) {
aib.update(i, a[i]);
}
while (m--) {
int cod, x, y; cin >> cod >> x >> y;
if (cod == 0)
aib.update(x, -y);
else
cout << aib.query(y) - aib.query(x - 1) << '\n';
}
return 0;
}