Pagini recente » Cod sursa (job #1779128) | Cod sursa (job #318155) | Cod sursa (job #2421226) | Cod sursa (job #225190) | Cod sursa (job #2375412)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int arbore[15001], val, t, x, y, n, m;
int leastSignBit(int x)
{
return (x & (-x));
}
int getSum(int nod)
{
int s = 0;
while (nod >= 1)
{
s += arbore[nod];
nod -= leastSignBit(nod);
}
return s;
}
void update(int nod, int val, bool ok)
{
while (nod <= n)
{
if (ok) arbore[nod] += val;
else arbore[nod] -= val;
nod = nod + leastSignBit(nod);
}
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; ++i)
{
fin >> val;
update(i, val, 1);
}
for (int i = 1; i <= m; ++i)
{
fin >> t >> x >> y;
if (t == 1)
{
fout << getSum(y) - getSum(x - 1) << '\n';
}
else
{
update(x, y, 0);
}
}
return 0;
}