Skip to content
Snippets Groups Projects
Commit 79ef7192 authored by Fernando K's avatar Fernando K
Browse files

Adiciona busca binária na árvore de Fenwick

parent f66bb900
No related branches found
No related tags found
No related merge requests found
......@@ -18,3 +18,17 @@ void add_inclusive(int a, int b, ll d) {
add(a, d);
add(b + 1, -d);
}
int lower_bound(ll t) {
ll sum = 0; int pos = 0;
for (int p = log2(N); p >= 0; p--) {
if (
pos + (1 << p) < N
&& sum + bit[pos + (1 << p)] < t
) {
sum += bit[pos + (1 << p)];
pos += (1 << p);
}
}
return pos;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment