Pagini recente » Cod sursa (job #2755345) | Cod sursa (job #714256) | Cod sursa (job #168310) | Cod sursa (job #2748178) | Cod sursa (job #220961)
Cod sursa(job #220961)
#include <fstream>
#include <stdlib.h>
using namespace::std;
int n,m,b,poz,c[15001];
ifstream in("datorii.in");
ofstream out("datorii.out");
void update(int locatie,int val)
{poz=0;
while(locatie<=n)
{c[locatie]+=val;
while(!(locatie&(1<<poz))) val++;
locatie+=(1<<poz);
poz++;
}}
void update2(int locatie,int val)
{poz=0;
while(locatie<=n)
{c[locatie]-=val;
while(!(locatie&(1<<poz))) val++;
locatie+=(1<<poz);
poz++;
}}
int interogare(int pozitie)
{int sum=0;poz=0;
while(pozitie>0)
{sum+=c[pozitie];
while(!(pozitie&(1<<poz))) poz++;
pozitie+=(1<<poz);
poz++;}
return sum;}
int main()
{ in>>n;in>>m;int aux,k,x,y;
for(int i=1;i<=n;i++)
{in>>aux;update(i,aux);}
for(;m;m--)
{in>>k>>x>>y;
if(k)
{out<<(interogare(y)-interogare(x-1))<<'\n';}
else
{update2(x,y);}}
return 0;
}