Pagini recente » Cod sursa (job #1737755) | Cod sursa (job #1758972) | Cod sursa (job #1263216) | Cod sursa (job #3322024) | Cod sursa (job #3330498)
#include <iostream>
#include <vector>
long long v[15005];
int n, m;
void update(int nod, int val)
{
for(; nod <= n; nod += (nod & -nod))
v[nod] += val;
}
long long query(int nod)
{
long long sum = 0;
for(; nod > 0; nod -= (nod & -nod))
sum += v[nod];
return sum;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
freopen("datorie.in", "r", stdin);
freopen("datorie.out", "w", stdout);
std::cin >> n >> m;
for(int i = 1; i <= n; i++)
{
int a;
std::cin >> a;
update(i, a);
}
for(int i = 1; i <= m; i++)
{
int op, a, b;
std::cin >> op >> a >> b;
if(op == 0)
{
update(a, -b);
}
else if(op == 1)
update(a, b);
else
std::cout << query(b) - query(a - 1) << "\n";
}
return 0;
}