Cod sursa(job #220961)

Utilizator Bogdan_CCebere Bogdan Bogdan_C Data 13 noiembrie 2008 21:21:02
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#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;
}