Pagini recente » Cod sursa (job #3142576) | Cod sursa (job #2529139) | Cod sursa (job #634407) | Cod sursa (job #162903) | Cod sursa (job #1877788)
/// Batog
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
const int maxn = 15005;
int V[maxn], B[maxn], rad;
inline int Bucket (int x) {
return (x / rad);
}
inline int First (int x) {
return (x * rad);
}
void Update(int pos, int val) {
V[pos] -= val;
B[Bucket(pos)] -= val;
}
int Query(int x, int y) {
int ans = 0, i;
int left = Bucket(x);
int right = Bucket(y);
for (i = left + 1; i < right; i++) {
ans += B[i];
}
for (i = x; i < First(left + 1); i++) {
ans += V[i];
}
for (i = First(right); i <= y; i++) {
ans += V[i];
}
return ans;
}
int main() {
ios_base :: sync_with_stdio (false);
int n, m, type, x, y, i;
fin >> n >> m;
rad = sqrt(n);
for (i = 1; i <= n; i++) {
fin >> V[i];
B[Bucket(i)] += V[i];
}
while (m--) {
fin >> type >> x >> y;
if (type == 0) {
Update(x, y);
} else {
fout << Query(x, y) << '\n';
}
}
fin.close();
fout.close();
return 0;
}