diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 6f7416fe..475fccfc 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -37,9 +37,9 @@ "tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp": "2026-03-09 12:21:26 -0600", "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-03-01 19:36:27 -0700", -"tests/library_checker_aizu_tests/data_structures/simple_tree_inc.test.cpp": "2026-03-01 19:36:27 -0700", -"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp": "2026-03-01 19:36:27 -0700", -"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp": "2026-03-01 19:36:27 -0700", +"tests/library_checker_aizu_tests/data_structures/simple_tree_inc.test.cpp": "2026-03-15 12:33:36 -0600", +"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp": "2026-03-15 12:33:36 -0600", +"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp": "2026-03-15 12:33:36 -0600", "tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp": "2026-03-01 19:36:27 -0700", "tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp": "2026-03-01 19:36:27 -0700", "tests/library_checker_aizu_tests/dsu/dsu.test.cpp": "2026-02-27 15:26:53 -0700", diff --git a/library/data_structures_[l,r)/seg_tree.hpp b/library/data_structures_[l,r)/seg_tree.hpp index d3015794..4421780d 100644 --- a/library/data_structures_[l,r)/seg_tree.hpp +++ b/library/data_structures_[l,r)/seg_tree.hpp @@ -6,18 +6,14 @@ //! return vl + vr; //! }); //! tree st(n, INT_MAX, ranges::min); -//! int idx = st.max_right(l, r, [&](int value) { +//! int idx = st.max_right(l, r, [&](int m, int value) { +//! // value = op(a[l], a[l+1], ..., a[m-1]) //! return value <= x; //! }); -//! // idx in [l, r] -//! // f(op(a[l], a[l+1], ..., a[idx-1])) is true -//! // f(op(a[l], a[l+1], ..., a[idx])) is false -//! idx = st.min_left(l, r, [&](int value) { +//! idx = st.min_left(l, r, [&](int m, int value) { +//! // value = op(a[m], ..., a[r-2], a[r-1]) //! return value <= x; //! }); -//! // idx in [l, r] -//! // f(op(a[idx], ..., a[r-2], a[r-1])) is true -//! // f(op(a[idx-1], ..., a[r-2], a[r-1])) is false //! @endcode //! @time O(n + q log n) //! @space O(n) diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp index 82d1d38a..3f615dbb 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp @@ -1,8 +1,8 @@ -int max_right(int l, int r, const auto& f) { +void max_right(int l, int r, const auto& f) { for (T x = unit; l < r;) { - int u = l + n, v = __lg(min(u & -u, r - l)); - if (T y = op(x, s[u >> v]); f(y)) l += 1 << v, x = y; - else r = l + (1 << v) - 1; + int u = l + n, v = __lg(min(u & -u, r - l)), + m = l + (1 << v); + if (T y = op(x, s[u >> v]); f(m, y)) l = m, x = y; + else r = m - 1; } - return l; } diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp index abd06ae1..65a71a98 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp @@ -1,9 +1,9 @@ -int min_left(int l, int r, const auto& f) { +void min_left(int l, int r, const auto& f) { for (T x = unit; l < r;) { - int u = r + n, v = __lg(min(u & -u, r - l)); - if (T y = op(s[(u - 1) >> v], x); f(y)) - r -= 1 << v, x = y; - else l = r - (1 << v) + 1; + int u = r + n, v = __lg(min(u & -u, r - l)), + m = r - (1 << v); + if (T y = op(s[(u - 1) >> v], x); f(m, y)) + r = m, x = y; + else l = m + 1; } - return r; } diff --git a/library/data_structures_[l,r]/seg_tree.hpp b/library/data_structures_[l,r]/seg_tree.hpp index ff3627a8..66171fd8 100644 --- a/library/data_structures_[l,r]/seg_tree.hpp +++ b/library/data_structures_[l,r]/seg_tree.hpp @@ -5,18 +5,14 @@ //! return vl + vr; //! }); //! tree st(a, ranges::min); -//! int idx = st.max_right(l, r, [&](int value) { +//! st.max_right(l, r, [&](int m, int value) { +//! // value = op(a[l], a[l+1], ..., a[m]) //! return value <= x; //! }); -//! // idx in [l, r+1] -//! // f(op(a[l], a[l+1], ..., a[idx-1])) is true -//! // f(op(a[l], a[l+1], ..., a[idx])) is false -//! idx = st.min_left(l, r, [&](int value) { +//! st.min_left(l, r, [&](int m, int value) { +//! // value = op(a[m], ..., a[r-1], a[r]) //! return value <= x; //! }); -//! // idx in [l-1, r] -//! // f(op(a[idx+1], ..., a[r-1], a[r])) is true -//! // f(op(a[idx], ..., a[r-1], a[r])) is false //! @endcode //! @time O(n + q log n) //! @space O(n) diff --git a/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp b/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp index ea43366c..48152e9b 100644 --- a/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp +++ b/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp @@ -1,9 +1,10 @@ -int max_right(int l, int r, const auto& f) { - if (T x = s[l + n]; f(x)) +void max_right(int l, int r, const auto& f) { + if (T x = s[l + n]; f(l, x)) for (l++; l <= r;) { - int u = l + n, v = __lg(min(u & -u, r - l + 1)); - if (T y = op(x, s[u >> v]); f(y)) l += 1 << v, x = y; - else r = l + (1 << v) - 2; + int u = l + n, v = __lg(min(u & -u, r - l + 1)), + m = l + (1 << v) - 1; + if (T y = op(x, s[u >> v]); f(m, y)) + l = m + 1, x = y; + else r = m - 1; } - return l; } diff --git a/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp b/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp index 99bcfbb4..e86e26c6 100644 --- a/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp +++ b/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp @@ -1,10 +1,11 @@ int min_left(int l, int r, const auto& f) { - if (T x = s[r + n]; f(x)) + if (T x = s[r + n]; f(r, x)) for (r--; l <= r;) { - int u = r + 1 + n, v = __lg(min(u & -u, r - l + 1)); - if (T y = op(s[(u - 1) >> v], x); f(y)) - r -= 1 << v, x = y; - else l = r - (1 << v) + 2; + int u = r + 1 + n, v = __lg(min(u & -u, r - l + 1)), + m = r - (1 << v) + 1; + if (T y = op(s[(u - 1) >> v], x); f(m, y)) + r = m - 1, x = y; + else l = m + 1; } return r; } diff --git a/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp b/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp index d06aac1a..af090cb5 100644 --- a/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/simple_tree_inc_line.test.cpp @@ -30,19 +30,25 @@ int main() { array res = st.query(l, r); { array walk_res = {1, 0}; - int idx = st.max_right(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.max_right(l, r, + [&](int m, + const array& curr_line) -> bool { + idx = m; walk_res = curr_line; return 1; }); assert(res == walk_res); - assert(idx == r + 1); + assert(idx == r); } { array walk_res = unit; - int idx = st.max_right(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.max_right(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 0; }); assert(walk_res == st.query(l, l)); @@ -50,19 +56,25 @@ int main() { } { array walk_res = unit; - int idx = st.min_left(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.min_left(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 1; }); assert(walk_res == res); - assert(idx == l - 1); + assert(idx == l); } { array walk_res = unit; - int idx = st.min_left(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.min_left(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 0; }); assert(walk_res == st.query(r, r)); 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 b465dcd8..c3c25a15 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,14 +22,20 @@ int main() { cout << st.query(k, k) << '\n'; } else if (type == 3) { // returns first element in [k,n-1] such that mx > 0 - int idx = st.max_right(k, n - 1, - [&](int mx) { return mx == 0; }); - if (idx == n) idx = -1; + int idx = -1; + st.max_right(k, n - 1, [&](int m, int mx) { + if (mx == 0) return 1; + idx = m; + return 0; + }); cout << idx << '\n'; } else { assert(type == 4); - cout << st.min_left(0, k, [&](int mx) { - return mx == 0; + int idx = -1; + cout << st.min_left(0, k, [&](int m, int mx) { + if (mx == 0) return 1; + idx = m; + return 0; }) << '\n'; } } diff --git a/tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp b/tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp index d817178c..8fbe326d 100644 --- a/tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp @@ -34,9 +34,12 @@ int main() { array res = st.query(l, r); { array walk_res = {1, 0}; - int idx = st.max_right(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.max_right(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 1; }); assert(res == walk_res); @@ -44,19 +47,25 @@ int main() { } { array walk_res = unit; - int idx = st.max_right(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.max_right(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 0; }); assert(walk_res == st.query(l, l + 1)); - assert(idx == l); + assert(idx == l + 1); } { array walk_res = unit; - int idx = st.min_left(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.min_left(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 1; }); assert(walk_res == res); @@ -64,13 +73,16 @@ int main() { } { array walk_res = unit; - int idx = st.min_left(l, r, - [&](const array& curr_line) -> bool { + int idx = -1; + st.min_left(l, r, + [&](int m, + const array& curr_line) -> bool { walk_res = curr_line; + idx = m; return 0; }); assert(walk_res == st.query(r - 1, r)); - assert(idx == r); + assert(idx == r - 1); } cout << (1LL * res[0] * x + res[1]) % mod << '\n'; } diff --git a/tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp b/tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp index 64e0a5d4..1ed81567 100644 --- a/tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp @@ -21,15 +21,22 @@ int main() { cout << st.query(k, k + 1) << '\n'; } else if (type == 3) { // returns first element in [k,n) such that mx > 0 - int idx = st.max_right(k, n, - [&](int mx) { return mx == 0; }); - if (idx == n) idx = -1; + int idx = -1; + st.max_right(k, n, [&](int m, int mx) { + if (mx == 0) return 1; + idx = m - 1; + return 0; + }); cout << idx << '\n'; } else { assert(type == 4); - cout << st.min_left(0, k + 1, - [&](int mx) { return mx == 0; }) - - 1 << '\n'; + int idx = -1; + st.min_left(0, k + 1, [&](int m, int mx) { + if (mx == 0) return 1; + idx = m; + return 0; + }); + cout << idx << '\n'; } } return 0;