Pagini recente » Cod sursa (job #2395553) | Cod sursa (job #138105) | Cod sursa (job #3170251) | Cod sursa (job #2944806) | Cod sursa (job #2845430)
#include<iostream>
#include<fstream>
using namespace std;
int n, m, i, j,aib[200005],v[200005],ans[200005],p,x,y;
void update(int pos,int val){
while (pos <= n) {
aib[pos] += val;
pos += pos & (-pos);
}
}
int querry(int pos) {
int ans = 0;
while (pos > 0) {
ans += aib[pos];
pos -= pos & (-pos);
}
return ans;
}
int cautarebinara(int elem) {
int st = 1, dr = n;
while (st <= dr) {
int mij = (st + dr) / 2;
if (querry(mij) < elem) st = mij + 1;
else dr = mij - 1;
}
return st;
}
int main() {
ifstream cin("datorii.in");
ofstream cout("datorii.out");
cin >> n>>m;
for (i = 1;i <= n;i++) {
cin >> v[i];
update(i, v[i]);
}
for (i = 1;i <= m;i++)
{
cin >> p;
if (p == 0) {
cin >> x >> y;
update(x, -y);
}
else {
cin >> x >> y;
cout << querry(y) - querry(x - 1)<<'\n';
}
}
}