Skip to content

Commit 040cc2d

Browse files
committed
update docs, I find this way easier
1 parent f833ab1 commit 040cc2d

File tree

1 file changed

+6
-5
lines changed
  • library/data_structures/bit_uncommon

1 file changed

+6
-5
lines changed
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
//! Requires s[i] >= 0
2-
//! max r such that sum of [0,r) < sum, or -1
1+
//! Requires sum of [i,i] >= 0
2+
//! Returns min r st sum of [0,r] >= sum
3+
//! Returns n if sum of [0,n-1] < sum
34
int walk(ll sum) {
45
if (sum <= 0) return -1;
56
int r = 0;
6-
for (int pw = bit_floor(size(s)); pw; pw >>= 1)
7-
if (r + pw <= sz(s) && s[r + pw - 1] < sum)
8-
sum -= s[(r += pw) - 1];
7+
for (int i = bit_floor(size(s)); i; i /= 2)
8+
if (r + i <= sz(s) && s[r + i - 1] < sum)
9+
sum -= s[(r += i) - 1];
910
return r;
1011
}

0 commit comments

Comments
 (0)