Pagini recente » Cod sursa (job #2920152) | Cod sursa (job #555737) | Cod sursa (job #2393053) | Cod sursa (job #245775) | Cod sursa (job #1144705)
#include <cstdio>
using namespace std;
FILE*f=fopen("datorii.in", "r");
FILE*g=fopen("datorii.out", "w");
int n, m, a[15010], i, t, x, y;
int lsb(int x){
return x&(-x);
}
void update(int p, int v){
while(p<=n)
{
a[p]+=v;
p+=lsb(p);
}
}
int querry(int p){
int s=0;
while(p>0)
{
s+=a[p];
p-=lsb(p);
}
return s;
}
int main(){
fscanf(f, "%d %d", &n, &m);
for(i=1; i<=n; i++)
{
fscanf(f, "%d", &x);
update(i, x);
}
for(i=1; i<=n; i++)
{
fscanf(f, "%d %d %d", &t, &x, &y);
if(t==0)
update(x, -y);
else
fprintf(g, "%d\n", querry(y)-querry(x-1));
}
return 0;
}