Skip to content

Commit cc93d62

Browse files
authored
Update segment tree walk logic with good flag
Refactor segment tree walk function to use a boolean flag for condition checking.
1 parent ffa57c7 commit cc93d62

File tree

1 file changed

+5
-3
lines changed
  • library/data_structures_[l,r]/seg_tree_uncommon

1 file changed

+5
-3
lines changed

library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ int walk(int l, int r, const auto& f) {
1313
return u - n;
1414
}
1515
*/
16+
bool good=0;
1617
while (l <= r) {
17-
int u = l + n, x = __lg(min(u & -u, r - l));
18-
if (f(s[u >> x])) r = l + (1 << x) - 1;
18+
int u = l + n, x = __lg(min(u & -u, r - l + 1));
19+
if (f(s[u >> x])) good=1,r = l + (1 << x) - 1;
1920
else l += 1 << x;
2021
}
21-
return -1;
22+
return good ? l ; -1;
23+
// return l;
2224
}

0 commit comments

Comments
 (0)