Skip to content
Merged

Golf #181

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c88f61
Enhance walk function with optimized logic
lrvideckis Feb 7, 2026
3beb2d1
Fix boundary condition in segment tree walk
lrvideckis Feb 7, 2026
0f954e4
[auto-verifier] verify commit 3beb2d193a58f8d1dc1d6fde6e03cf5600d88b7a
web-flow Feb 7, 2026
4db7b00
Fix boundary condition in segment tree walk function
lrvideckis Feb 7, 2026
267032c
Fix bug in segment tree walk function
lrvideckis Feb 7, 2026
ffa57c7
[auto-verifier] verify commit 267032c5a5b9ab40d785edea8bb77bf253ed9845
web-flow Feb 7, 2026
cc93d62
Update segment tree walk logic with good flag
lrvideckis Feb 7, 2026
5e83a0a
[auto-verifier] verify commit cc93d6221e77510e17f3551bc23f44c5215d482e
web-flow Feb 7, 2026
42d4c51
Fix loop condition in segment tree walk function
lrvideckis Feb 7, 2026
3f31866
Fix return statement syntax in walk.hpp
lrvideckis Feb 7, 2026
fce30fb
[auto-verifier] verify commit 3f31866b5d8d39b8a3f19462c75a604fda7dbc20
web-flow Feb 7, 2026
b741e86
Fix loop condition and variable initialization in walk.hpp
lrvideckis Feb 7, 2026
e43234d
[auto-verifier] verify commit b741e864771cb6c048bde39a56d78be8e9c1abc4
web-flow Feb 7, 2026
a837375
Update walk.hpp
lrvideckis Feb 7, 2026
42e22a5
[auto-verifier] verify commit a837375fb537d6061d7a63f0b7e99ce52360d9bc
web-flow Feb 7, 2026
b9c25bc
more golf!
lrvideckis Feb 7, 2026
8ea2e9e
[auto-verifier] verify commit b9c25bcda59f3465f0eb62c10a3f54bf32f91939
web-flow Feb 7, 2026
5743f65
Reverse conditions in walk function logic
lrvideckis Feb 8, 2026
1ea3e05
Change condition in walk function for sum check
lrvideckis Feb 8, 2026
6405c5e
Fix comment to clarify index search condition
lrvideckis Feb 8, 2026
ad92a0b
[auto-verifier] verify commit 6405c5e3c6e93b56663ca377efd005b04cdba868
web-flow Feb 8, 2026
434c09a
format
lrvideckis Feb 8, 2026
cb6f4cf
[auto-verifier] verify commit 434c09a29b291761e0b7b71ffceee2c4aead9de9
web-flow Feb 8, 2026
abdb86b
Fix formatting of if statement in test code
lrvideckis Feb 8, 2026
827ed32
[auto-verifier] verify commit abdb86b64b4a15881d41b325f320f318670cdaf6
web-flow Feb 8, 2026
7949f33
format
lrvideckis Feb 8, 2026
b19e3d6
[auto-verifier] verify commit 7949f3366b38b90cacb049f73fe56999bf31e188
web-flow Feb 8, 2026
47f30e9
Merge branch 'dev' into golf
lrvideckis Feb 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@
"tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp": "2026-01-18 11:15:41 +0000",
"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp": "2026-01-18 11:15:41 +0000",
"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp": "2026-01-18 11:15:41 +0000",
"tests/library_checker_aizu_tests/data_structures/simple_tree.test.cpp": "2026-02-07 20:45:45 +0000",
"tests/library_checker_aizu_tests/data_structures/simple_tree_inc.test.cpp": "2026-02-05 16:06:35 -0700",
"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp": "2026-02-05 16:06:35 -0700",
"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp": "2026-02-05 16:06:35 -0700",
"tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp": "2026-02-07 20:45:45 +0000",
"tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp": "2026-02-07 20:45:45 +0000",
"tests/library_checker_aizu_tests/flow/dinic_aizu.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2024-11-17 14:04:03 -0600",
"tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2024-12-05 10:41:42 -0600",
Expand Down
2 changes: 1 addition & 1 deletion library/data_structures_[l,r]/seg_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! tree st(n, INT_MAX, ranges::min);
//! int idx = st.walk(l, r, [&](int value) {
//! return value <= x;
//! }); // smallest index in [l, r] s.t. f is true
//! }); // smallest index in [l, r] s.t. f is false
//! }
//! @endcode
//! @time O(n + q log n)
Expand Down
14 changes: 6 additions & 8 deletions library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
int walk(int l, int r, const auto& f) {
for (l += n, r += n; l <= r;)
if (int u = nxt(l, r); f(s[u])) {
while (u < n)
if (f(s[2 * u])) u *= 2;
else (u *= 2)++;
return u - n;
}
return -1;
while (l <= r) {
int u = l + n, x = __lg(min(u & -u, r - l + 1));
if (f(s[u >> x])) l += 1 << x;
else r = l + (1 << x) - 2;
}
return l;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ int main() {
cout << st.query(k, k) << '\n';
} else if (type == 3) {
// returns first element in [k,n-1] such that sum > 0
cout << st.walk(k, n - 1, [&](int sum) {
return sum > 0;
}) << '\n';
int idx = st.walk(k, n - 1,
[&](int sum) { return sum == 0; });
if (idx == n) idx = -1;
cout << idx << '\n';
} else {
assert(type == 4);
int total = st.query(0, k);
Expand All @@ -33,8 +34,10 @@ int main() {
} else {
int pref_sum = 0;
cout << st.walk(0, k, [&](int sum) {
if (pref_sum + sum == total) return 1;
pref_sum += sum;
if (pref_sum + sum < total) {
pref_sum += sum;
return 1;
}
return 0;
}) << '\n';
}
Expand Down
Loading