Mai intai trebuie sa te autentifici.
Cod sursa(job #1246248)
Utilizator | Data | 20 octombrie 2014 20:12:23 | |
---|---|---|---|
Problema | Datorii | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.89 kb |
#include <cstdio>
#define NRM 150000
using namespace std;
long n,m,i,l,val,ind,poz,x,dr,st,s1,s2;
long a[NRM];
long query(long x)
{
long s = 0;
for (; x; x -= x ^ (x-1) & x)
s += a[x];
return s;
}
void update(long x, long v)
{
for (; x <= n; x += x^(x-1) & x)
a[x] += v;
}
int main(){
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
scanf("%ld %ld",&n,&m);
for (i=1;i<=n;i++){
scanf("%ld",&val);
update(i,val);
}
for(i=1;i<=m;i++)
{
scanf ("%ld",&l);
if(l==1){
scanf("%ld %ld",&st,&dr);
s1=query(dr);
s2=query(st-1);
printf("%ld\n",s1-s2);
}
else{
scanf("%ld %ld",&ind,&val);
update(ind,-val);
}
}
printf("\n");
return 0;
}