Pagini recente » Cod sursa (job #2208883) | Cod sursa (job #737161) | Cod sursa (job #3167404) | Cod sursa (job #3196935) | Cod sursa (job #337297)
Cod sursa(job #337297)
#include <stdio.h>
#include <fstream>
using namespace std;
int n,m,t,c,s;
int arb[100010];
inline int minim(int a, int b)
{
if(a>b) return b;
return a;
}
void updateplus(int poz, int val)
{
c = 0;
while(poz<=n)
{
arb[poz]+=val;
while(!(poz&(1<<c))) c++;
poz+=(1<<c);
c+=1;
}
}
void updateminus(int poz, int val)
{
c = 0;
while(poz<=n)
{
arb[poz]-=val;
while(!(poz&(1<<c))) c++;
poz+=(1<<c);
c+=1;
}
}
int query(int poz)
{
c=0;
s=0;
while(poz>0)
{
s+=arb[poz];
while(!(poz&(1<<c))) c++;
poz-=(1<<c);
c+=1;
}
return s;
}
int main()
{
freopen("datorii.in","r",stdin);
freopen("datorii.out","w",stdout);
int cod,x,y;
scanf("%d%d", &n, &m);
for(int i=1;i<=n;++i)
{
scanf("%d", &t);
updateplus(i,t);
}
for ( ; m; m-- )
{
scanf("%d", &cod);
scanf("%d%d", &x, &y);
if (cod==0 ) updateminus(x,y);
else printf("%d\n", query(y)-query(x-1));
}
return 0;
}