# Cod sursa(job #2750399)

Utilizator Data 11 mai 2021 00:17:27 Datorii 0 cpp-64 done Arhiva de probleme 1.49 kb
``````#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define NMAX .
#define cin fin
#define cout fout
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
template <class T>
class arbind
{
int n;

vector<T> aib;
inline int lsb(int x)
{
return x & (-x);
}

public:
arbind(int size)
{
n=size;
aib.reserve(size + 10);

}
void init(const vector<int> &v, int size_1)
{
for (int i = 1; i <= size_1; i++)
{
update(i, v[i]);
}
}

void update(int pos, T val)
{
for (int i = pos; i <= n; i += lsb(i))
aib[i] += val;
}
void update1(int pos, T val)
{
for (int i = pos; i <= n; i += lsb(i))
aib[i] -= val;
}
T query(int pos)
{
T sum = 0;
for (int i = pos; i >= 1; i -= lsb(i))
sum += aib[i];
return sum;
}
};
int32_t main()
{
int i;
int n, q;
vector<int> sol;
sol.push_back(0);
cin >> n >> q;
for (i = 1; i <= n; i++)
{
int x;
cin >> x;
sol.push_back(x);
}
arbind<int> a(n);
a.init(sol, n);
for (int it = 0; it < q; it++)
{
int t, x, y;
cin >> t;
if (t == 1)
{
cin >> x >> y;
cout << a.query(y) - a.query(x - 1) << '\n';
}
else if (!t)
{
cin >> x >> y;
a.update1(x, y);
}
}

return 0;
}
``````