Pagini recente » Cod sursa (job #3246781) | Cod sursa (job #860511) | Cod sursa (job #1983759) | Cod sursa (job #1838055) | Cod sursa (job #2710683)
#include <iostream>
#include <fstream>
#define u(x) ((x ^ (x - 1)) & x)
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, m, op;
int aib[15005], v[15005];
void Update(int poz, int x)
{
for (int i = poz; i <= n; i += u(i))
aib[i] += x;
}
void UpdateRestanta(int poz, int x)
{
for (int i = poz; i <= n; i += u(i))
aib[i] -= x;
}
int Query(int poz)
{
int i, sum = 0;
for (i = poz; i > 0; i -= u(i))
sum += aib[i];
return sum;
}
int main()
{
int i;
int x, y;
fin >> n >> m;
for (i = 1; i <= n; ++i)
{
fin >> v[i];
Update(i, v[i]);
}
for (i = 1; i <= m; ++i)
{
fin >> op >> x >> y;
if (op == 1)
fout << Query(y) - Query(x - 1) << "\n";
else
UpdateRestanta(x, y);
}
return 0;
}