Pagini recente » Cod sursa (job #2281167) | Cod sursa (job #1081152) | Cod sursa (job #2503918) | Cod sursa (job #370443) | Cod sursa (job #3139278)
#include <iostream>
using namespace std;
#define zeros(x) ( (x ^ (x - 1)) & x )
int AIB[15000],n;
void Add(int x, int quantity) {
for (int i = x; i <= n; i += zeros(i))
AIB[i] += quantity;
}
int Compute(int x) {
int ret = 0;
for (int i = x; i > 0; i -= zeros(i))
ret += AIB[i];
return ret;
}
int main()
{
int m,i,q,a,b,t;
FILE *fin, *fout;
fin=fopen("datorii.in", "r");
fout=fopen("datorii.out", "w");
fscanf(fin, "%d %d", &n, &m);
for(i=1;i<=n;i++) {
fscanf(fin, "%d", &q);
Add(i, q);
}
for(i=1;i<=m;i++) {
fscanf(fin, "%d %d %d", &t, &a, &b);
if(t == 1) fprintf(fout, "%d\n", Compute(b) - Compute(a-1));//cout << Compute(b) - Compute(a-1)<<'\n';
else Add(a, -b);
}
fclose(fout);
return 0;
}