Pagini recente » Cod sursa (job #2793146) | Cod sursa (job #2040153) | Cod sursa (job #1045392) | Cod sursa (job #832442) | Cod sursa (job #220963)
Cod sursa(job #220963)
#include <fstream>
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;
locatie+=((locatie^(locatie-1))&locatie);
}}
void update2(int locatie,int val)
{poz=0;
while(locatie<=n)
{c[locatie]-=val;
locatie+=((locatie^(locatie-1))&locatie);
}}
int interogare(int pozitie)
{int sum=0;poz=0;
while(pozitie>0)
{sum+=c[pozitie];
pozitie-=((pozitie^(pozitie-1))&pozitie);
}
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;
}