Pagini recente » Cod sursa (job #2664130) | Cod sursa (job #29987) | Cod sursa (job #3182735) | Cod sursa (job #112996) | Cod sursa (job #2398266)
#include <bits/stdc++.h>
#define up(x) (x&-x)
#define nmax 15005
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n, m;
int a[nmax];
void add(int pos, int val)
{
for (int i = pos; i <= n; i += up(i))
a[i] += val;
}
int compute(int x)
{
int sum = 0;
for (int i = x; i > 0; i -= up(i))
sum += a[i];
return sum;
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i ++)
{
int x;
fin >> x;
add(i, x);
}
for (int i = 1; i <= m; i ++)
{
int a, b, c;
fin >> a >> b >> c;
if (a == 0)
add(b, -c);
else
fout << compute(c) - compute(b-1) << "\n";
}
}