Pagini recente » Cod sursa (job #157949) | Cod sursa (job #1418944) | Cod sursa (job #1781031) | Cod sursa (job #2754895) | Cod sursa (job #634574)
Cod sursa(job #634574)
#include <stdio.h>
#define NMAX 15010
int tree[NMAX];
int N;
int read(int idx)
{
int sum = 0;
while (idx > 0) {
sum += tree[idx];
idx -= (idx & -idx);
}
return sum;
}
void update(int idx, int val)
{
while (idx <= N) {
tree[idx] += val;
idx += (idx & -idx);
}
}
int main()
{
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
int M, i, x, y, type;
scanf("%d %d", &N, &M);
for (i=1; i<=N; ++i) {
scanf("%d", &x);
update(i, x);
}
for (i=1; i<=M; ++i) {
scanf("%d", &type);
if (!type) {
scanf("%d %d", &x, &y);
update(x, -y);
}
else {
scanf("%d %d", &x, &y);
printf("%d\n", read(y) - read(x-1));
}
}
return 0;
}