Pagini recente » Cod sursa (job #2883243) | Cod sursa (job #871612) | Cod sursa (job #2287765) | Cod sursa (job #1757704) | Cod sursa (job #524947)
Cod sursa(job #524947)
// pb007.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "stdio.h"
int a[15002] = { 0 }, arb[15002] = { 0 };
int n = 0, m = 0;
int modif(int pos, int nr)
{
int sum = 0;
while (pos <= n)
{
arb[pos] -= nr;
int pos1 = pos;
int nZeros = 0;
while (pos1 % 2 == 0)
{
nZeros++;
pos1 = pos1 >> 1;
}
pos += (1 << nZeros);
}
return 0;
}
int suma(int pos)
{
int sum = 0;
while (pos > 0)
{
sum += arb[pos];
int pos1 = pos;
int nZeros = 0;
while (pos1 % 2 == 0)
{
nZeros++;
pos1 = pos1 >> 1;
}
pos -= (1 << nZeros);
}
return sum;
}
int main()
{
FILE *f = fopen("datorii.in", "rt");
if (!f)
return 0;
fscanf(f, "%d %d", &n, &m);
int i = 0;
for (i = 1; i <= n; i++)
{
fscanf(f, "%d", &a[i]);
modif(i, -a[i]);
}
int o = 0, x = 0, y = 0;
FILE *fres = fopen("datorii.out", "wt");
if (!fres)
{
fclose(f);
return 0;
}
int sum = 0, j = 0;
for (i = 1; i <= m; i++)
{
fscanf(f, "%d %d %d", &o, &x, &y);
switch (o)
{
case 0: modif(x, y);
break;
case 1:
fprintf(fres, "%d\n", suma(y) - (x > 1 ? suma(x - 1) : 0));
break;
}
}
fclose(fres);
fclose(f);
return 0;
}