diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index dd4cbf0e..da2b28e7 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -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", diff --git a/library/data_structures_[l,r]/seg_tree.hpp b/library/data_structures_[l,r]/seg_tree.hpp index df0f4f57..d0dd7489 100644 --- a/library/data_structures_[l,r]/seg_tree.hpp +++ b/library/data_structures_[l,r]/seg_tree.hpp @@ -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) diff --git a/library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp b/library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp index 03e61ddf..c3ef7dbb 100644 --- a/library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp +++ b/library/data_structures_[l,r]/seg_tree_uncommon/walk.hpp @@ -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; } diff --git a/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp b/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp index 1dd9fcf9..50c2ea3f 100644 --- a/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp @@ -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); @@ -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'; }