Pagini recente » Teme Pregatire ACM Unibuc 2014, Anul II | Cod sursa (job #1581745) | Cod sursa (job #38864) | Cod sursa (job #1581731) | Cod sursa (job #3244705)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
const int NMAX = 15001;
int n, m;
///AIB
int v[NMAX];
void update(int poz, int val)
{
while(poz <= n)
{
v[poz] += val;
poz += poz & (-poz);
}
}
int query(int poz)
{
int sum = 0;
while(poz > 0)
{
sum += v[poz];
poz -= poz & (-poz);
}
return sum;
}
int RangeSum(int x, int y)
{
return query(y) - query(x - 1);
}
///
void ReadAndInit()
{
int x;
f >> n >> m;
for(int i = 1; i <= n; i++)
{
f >> x;
update(i, x);
}
}
void ProcessQueries()
{
int tip, x, y;
for(int i = 1; i <= m; i++)
{
f >> tip >> x >> y;
if(tip == 0)
update(x, -y);
else
g << RangeSum(x, y) << '\n';
}
}
int main()
{
ReadAndInit();
ProcessQueries();
return 0;
}