Pagini recente » Cod sursa (job #2369488) | Cod sursa (job #2523170) | Cod sursa (job #2242348) | Cod sursa (job #1455041) | Cod sursa (job #2348488)
/*
* Software sellers want to divide the users and conquer them, making each user agree not to share with others.
* Richard M. Stallman
*/
#include <fstream>
#include <iostream>
const int MAX_N = 100000;
const int MAX_LOG_N = 17;
struct {
int data[MAX_N + 1];
int n;
}aib;
int computeSum(int i)
{
int sum = 0;
while(i != 0)
{
sum += aib.data[i];
i -= i & (-i);
}
return sum;
}
void update(int i, int v)
{
while(i <= aib.n)
{
aib.data[i] += v;
i += i & (-i);
}
}
int main()
{
std::ifstream fin("datorii.in");
std::ofstream fout("datorii.out");
int n, k;
fin >> n >> k;
aib.n = n;
for(int i = 1; i <= n; i++)
{
int x;
fin >> x;
update(i, x);
}
void (*branches[2])(std::ofstream&, int, int) = {
[](std::ofstream&, int a, int b) { update(a, -b); },
[](std::ofstream& fout, int a, int b) { fout << computeSum(b) - (a == 1 ? 0 : computeSum(a - 1)) << '\n'; },
};
for(; k > 0; k--)
{
int x, a, b;
fin >> x;
fin >> a >> b;
branches[x](fout, a, b);
}
}