Pagini recente » Cod sursa (job #1780495) | Cod sursa (job #1278688) | Cod sursa (job #2053802) | Cod sursa (job #252832) | Cod sursa (job #1551695)
#include <iostream>
#include <fstream>
#define nmax 15005
using namespace std;
int aib[nmax], n, m, x, y, act;
inline int bit(int x)
{
return (x &(-x));
}
void update(int poz, int val)
{
for(int i=poz; i<=n; i+=bit(i))
{
aib[i]+=val;
}
return;
}
int find(int poz)
{
int sum = 0;
for(int i = poz; i>=1; i-=bit(i))
{
sum+=aib[i];
}
return sum;
}
int querry(int x, int y)
{
x = find(x-1);
y = find(y);
return (y-x);
}
int main()
{
ifstream f("datorii.in");
ofstream g("datorii.out");
f >> n >> m;
for(int i=1; i<=n; i++)
{
f >> y;
update(i, y);
}
for(int i=1; i<=m; i++)
{
f >> act >> x >> y;
if (act == 0)
{
update(x, -y);
}else{
g << querry(x, y)<<"\n";
}
}
f.close();
g.close();
return 0;
}