Skip to content

Commit 75ed507

Browse files
committed
change functionality of lambda
1 parent 2ea0b33 commit 75ed507

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
int walk(int l, int r, const auto& f) {
2-
while (l <= r) {
3-
int u = l + n, v = __lg(min(u & -u, r - l + 1));
4-
if (f(s[u >> v])) l += 1 << v;
5-
else r = l + (1 << v) - 2;
2+
for (int u = l + n, v = __lg(min(u & -u, r - l + 1)); v >= 0; v--) {
3+
if (T x = s[u >> v]; f(x)) {
4+
l += 1 << v;
5+
while (l <= r) {
6+
u = l + n, v = __lg(min(u & -u, r - l + 1));
7+
if (T y = op(x, s[u >> v]); f(y)) l += 1 << v, x = y;
8+
else r = l + (1 << v) - 2;
9+
}
10+
break;
11+
} else r = l + (1 << v) - 2;
612
}
713
return l;
814
}

tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#define PROBLEM \
22
"https://judge.yosupo.jp/problem/predecessor_problem"
33
#include "../template.hpp"
4+
int __lg(unsigned x) {
5+
return bit_width(x) - 1;
6+
}
47
#include "../../../library/data_structures_[l,r]/seg_tree.hpp"
58
int main() {
69
cin.tie(0)->sync_with_stdio(0);
@@ -32,13 +35,8 @@ int main() {
3235
if (total == 0) {
3336
cout << -1 << '\n';
3437
} else {
35-
int pref_sum = 0;
3638
cout << st.walk(0, k, [&](int sum) {
37-
if (pref_sum + sum < total) {
38-
pref_sum += sum;
39-
return 1;
40-
}
41-
return 0;
39+
return sum < total;
4240
}) << '\n';
4341
}
4442
}

0 commit comments

Comments
 (0)