Pagini recente » Cod sursa (job #3191400) | Cod sursa (job #1954058) | Cod sursa (job #868350) | Cod sursa (job #2195069) | Cod sursa (job #1962135)
#include <stdio.h>
using namespace std;
FILE*f=fopen("datorii.in","r");
FILE*g=fopen("datorii.out","w");
int n,arb[15010];
void adaug(int p, int x){
int b;
while (p<=n){
arb[p]+=x;
b=p&((p-1)^p);
p+=b;
}
}
int suma(int p){
int b,s=0;
while (p>0){
s+=arb[p];
b=p&((p-1)^p);
p-=b;
}
return s;
}
int main()
{
int m,p,x,y,i;
fscanf(f,"%d%d",&n,&m);
for (i=1;i<=n;i++){
fscanf(f,"%d",&x);
adaug(i,x);
}
for (i=1;i<=m;i++){
fscanf(f,"%d%d%d",&p,&x,&y);
if (p==0){
adaug(x,-y);
}
else{
fprintf(g,"%d\n",suma(y)-suma(x-1));
}
}
fclose(f);
fclose(g);
return 0;
}