Pagini recente » Cod sursa (job #2486885) | Cod sursa (job #3120489) | Cod sursa (job #2572480) | Cod sursa (job #2035956) | Cod sursa (job #2750656)
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
char buff[4096];
int pbuf=4095;
void readbuff()
{
pbuf=0;
fin.read(buff,4095);
}
int citire()
{
int nr=0;
if(pbuf==4095)
{
readbuff();
}
while(buff[pbuf]<'0'||buff[pbuf]>'9')
{
pbuf++;
if(pbuf==4095)
{
readbuff();
}
}
while(buff[pbuf]>='0'&&buff[pbuf]<='9')
{
nr=nr*10+buff[pbuf]-'0';
pbuf++;
if(pbuf==4095)
{
readbuff();
}
}
return nr;
}
int aib[15005],cnt;
int n;
void update(int poz,int val)
{
while(poz<=n)
{
aib[poz]+=val;
poz+=poz&-poz;
}
}
int query(int poz)
{
cnt=0;
while(poz>0)
{
cnt+=aib[poz];
poz-=poz&-poz;
}
return cnt;
}
int main()
{
int m,tip,a,b;
n=citire();m=citire();
for(int i=1;i<=n;i++)
{
a=citire();
update(i,a);
}
for(int i=1;i<=m;i++)
{
tip=citire();a=citire();b=citire();
if(tip==0)
{
update(a,-b);
}
else
{
fout<<query(b)-query(a-1)<<'\n';
}
}
return 0;
}