Pagini recente » Profil hamed | Rating Robert Bindar (robertbindar) | Cod sursa (job #1998246) | Cod sursa (job #2672950) | Cod sursa (job #2156839)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <bitset>
#include <set>
#include <list>
using namespace std;
int aib[15005];
int n;
void update(int idx, int val) {
for (; idx <= n; idx += idx & (-idx))
aib[idx] += val;
}
int query(int idx) {
int res = 0;
for (; idx > 0; idx -= idx & (-idx))
res += aib[idx];
return res;
}
int main() {
ios::sync_with_stdio(false);
string filename = "datorii";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
int m;
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
int x;
fin >> x;
update(i, x);
}
while (m--) {
int typeOp, a, b;
fin >> typeOp >> a >> b;
if (typeOp == 0) update(a, -b);
else fout << query(b) - query(a - 1) << "\n";
}
//system("pause");
return 0;
}