Pagini recente » Cod sursa (job #451277) | Cod sursa (job #1558957) | Cod sursa (job #2686541) | Cod sursa (job #1210876) | Cod sursa (job #3254440)
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#warning That's not the baby, that's my baby
#define debug(x) #x << " = " << x << '\n'
using ll = long long;
const ll INF = 1e18;
const int NMAX = 2e5;
const int BS = 400;
struct Nr {
ll x;
Nr() : x(0) {}
Nr(ll _x) : x(_x) {}
Nr operator + (const Nr &other) const {
return Nr(x + other.x);
};
};
Nr bucket[NMAX / BS + 1];
Nr a[NMAX + 1];
int n;
void refresh(int b) {
int l = std::max(1, b * BS);
int r = std::min(n, (b + 1) * BS - 1);
bucket[b] = 0;
for (int i = l; i <= r; i++) {
bucket[b] = bucket[b] + a[i];
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#else
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
#endif
int q;
std::cin >> n >> q;
for (int i = 1; i <= n; i++) {
std::cin >> a[i].x;
bucket[i / BS] = bucket[i / BS] + a[i];
}
while (q--) {
int type;
std::cin >> type;
if (type == 0) {
int x, y;
std::cin >> x >> y;
a[x].x -= y;
refresh(x / BS);
} else {
int l, r;
std::cin >> l >> r;
if (r - l + 1 <= BS){
Nr answer = 0;
for (int i = l; i <= r; i++) {
answer = answer + a[i];
}
std::cout << answer.x << '\n';
} else {
Nr answer = 0;
int bl = l / BS;
int br = r / BS;
for (int i = bl + 1; i < br; i++) {
answer = answer + bucket[i];
}
for (int i = l; i < (bl + 1) * BS; i++) {
answer = answer + a[i];
}
for (int i = br * BS; i <= r; i++) {
answer = answer + a[i];
}
std::cout << answer.x << '\n';
}
}
}
return 0;
}