Pagini recente » Cod sursa (job #1842799) | Cod sursa (job #2053701) | Cod sursa (job #1536523) | Cod sursa (job #1850341) | Cod sursa (job #2595926)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int DIM = 15005;
int n,m,AIB[DIM],event,a,b,x;
void UpdateArray(int pos, int value, int ok)
{
do
{
if(ok)
AIB[pos]+=value;
else
AIB[pos]-=value;
pos+=pos&-pos;
}while(pos<=n);
}
int QueryArray(int pos)
{
int ans=0;
while(pos)
{
ans+=AIB[pos];
pos&=pos-1;
}
return ans;
}
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)
{
fin>>x;
UpdateArray(i,x,1);
}
for(int i=1;i<=m;i++)
{
fin>>event>>a>>b;
switch(event)
{
case 0:
{
UpdateArray(a,b,0);
break;
}
default:
{
fout<<(QueryArray(b)-QueryArray(a-1))<<'\n';
break;
}
}
}
}