Pagini recente » Cod sursa (job #2941654) | Cod sursa (job #817925) | Cod sursa (job #3268793) | Cod sursa (job #2127611) | Cod sursa (job #2602190)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int v[MAXN], aib[MAXN];
int n;
int lsb(int x){
return (x & -x);
}
void update(int pos, int val){
while(pos <= n){
aib[pos] += val;
pos += lsb(pos);
}
}
int query(int pos){
int ans = 0;
while(pos){
ans += aib[pos];
pos -= lsb(pos);
}
return ans;
}
int main()
{
ifstream fin("aib.in");
ofstream fout("aib.out");
ios::sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
int m;
fin >> n >> m;
for(int i = 1; i <= n; ++i){
fin >> v[i];
update(i, v[i]);
}
while(m--){
int c, a, b;
fin >> c >> a;
if(c < 2) fin >> b;
if(c == 0) update(a, b);
else if(c == 1) fout << query(b) - query(a - 1) << "\n";
else{
int k = 1;
while(k <= n && query(k) < a) k += lsb(k);
if(aib[k] == a) fout << k << "\n";
else fout << "-1\n";
}
}
return 0;
}