Pagini recente » Cod sursa (job #2215132) | Cod sursa (job #235007) | Cod sursa (job #3154114) | Cod sursa (job #308819) | Cod sursa (job #2829262)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
#define debugsp(x) cerr << #x << " " << x << ' '
using namespace std;
ifstream in ("aib.in");
ofstream out ("aib.out");
const int INF = 2e9;
const int N = 100000;
int aib[1 + N];
int n, m;
void update(int nod, int val) {
for (int i = nod; i <= n; i += (i & (-i)))
aib[i] += val;
}
int query(int nod) {
int s = 0;
for (int i = nod; i >= 1; i -= (i & (-i)))
s += aib[i];
return s;
}
int cautbin(int x) {
int r, pas;
r = 0;
pas = 1 << 17;
while (pas) {
if (r + pas <= n && query(r + pas) <= x)
r += pas;
pas /= 2;
}
if (query(r) == x)
return r;
return -1;
} // log^2
int cautbinmaibun(int x) {
int r, pas, cursum = 0;
r = 0; pas = 1 << 17;
while (pas) {
if (r + pas <= n && cursum + aib[r + pas] <= x) {
cursum += aib[r + pas];
r += pas;
if (cursum == x) {
return r;
}
}
pas >>= 1;
}
return -1;
}
int main() {
in >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
in >> x;
update(i, x);
}
for (int i = 1; i <= m; i++) {
int t, x, y;
in >> t >> x;
if (t != 2) in >> y;
if (t == 0)
update(x, y);
else if (t == 1)
out << query(y) - query(x - 1) << '\n';
else out << cautbinmaibun(x) << '\n';
}
return 0;
}