Pagini recente » Cod sursa (job #934089) | Cod sursa (job #2598535) | Cod sursa (job #1060212) | Cod sursa (job #2758890) | Cod sursa (job #2564766)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int NMAX = 100009;
int n,m;
int tree[NMAX];
void Update(int pos, int val)
{
while(pos <=n )
{
tree[pos] += val;
pos += (pos &(-pos));
}
}
int Query(int pos)
{
int sum = 0;
while( pos )
{
sum += tree[pos];
pos -= (pos &(-pos));
}
return sum;
}
void Read()
{
int i,j,x,a,b;
fin>>n>>m;
for(i=1; i<=n; ++i)
{
fin>>x;
Update(i,x);
}
for(i=1; i<=m; ++i)
{
fin>>x>>a>>b;
if( x == 0)
{
Update ( a, -b );
}
else fout<<Query(b) - Query(a-1)<<"\n";
}
}
int main()
{
Read();
return 0;
}