Pagini recente » Istoria paginii runda/shimulare_shmecheri/clasament | Istoria paginii runda/igorj_5/clasament | Monitorul de evaluare | Cod sursa (job #1593531) | Cod sursa (job #2379056)
#include <bits/stdc++.h>
#define MAX 15005
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
int n, m;
int a, b;
int aib[MAX];
void update (int pos, int val)
{
while (pos <= n) {
aib[pos] += val;
pos += (pos & (-pos));
}
}
int read(int pos)
{
int sum = 0;
while (pos) {
sum += aib[pos];
pos -= (pos & (-pos));
}
return sum;
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i ++) {
fin >> a;
update(i, a);
}
bool test;
for (int i = 1; i <= m; i ++) {
fin >> test >> a >> b;
if (test) fout << read(b) - read(a - 1) << "\n";
else update(a, -b);
}
return 0;
}