diff --git a/library/data_structures_[l,r)/bit.hpp b/library/data_structures_[l,r)/bit.hpp index 3024a16f..1e3bf04a 100644 --- a/library/data_structures_[l,r)/bit.hpp +++ b/library/data_structures_[l,r)/bit.hpp @@ -1,10 +1,7 @@ #pragma once //! @code //! BIT bit(n); -//! bit.walk([&](int r, int64_t sum) -> bool { -//! // sum = a[0] + a[1] + ... + a[r - 1] -//! }); -//! int r = bit.walk2(sum); +//! int r = bit.walk(sum); //! // Returns min r s.t. sum of [0,r+1) >= sum //! // Returns n if sum of [0,n) < sum //! // Returns -1 if sum <= 0 @@ -25,6 +22,5 @@ struct BIT { return res; } ll query(int l, int r) { return query(r) - query(l); } -#include "bit_uncommon/walk_lambda.hpp" #include "bit_uncommon/walk.hpp" }; diff --git a/library/data_structures_[l,r)/bit_uncommon/walk.hpp b/library/data_structures_[l,r)/bit_uncommon/walk.hpp index 20c3a732..40ce10d7 100644 --- a/library/data_structures_[l,r)/bit_uncommon/walk.hpp +++ b/library/data_structures_[l,r)/bit_uncommon/walk.hpp @@ -1,4 +1,4 @@ -int walk2(ll sum) { +int walk(ll sum) { if (sum <= 0) return -1; int r = 0; for (int i = bit_floor(size(s)); i; i /= 2) diff --git a/library/data_structures_[l,r)/bit_uncommon/walk_lambda.hpp b/library/data_structures_[l,r)/bit_uncommon/walk_lambda.hpp deleted file mode 100644 index fe55e883..00000000 --- a/library/data_structures_[l,r)/bit_uncommon/walk_lambda.hpp +++ /dev/null @@ -1,6 +0,0 @@ -void walk(auto f) { - ll sum = 0; - for (int i = bit_floor(size(s)), r = 0; i; i /= 2) - if (r + i <= sz(s) && f(r + i, sum + s[r + i - 1])) - sum += s[(r += i) - 1]; -} diff --git a/library/data_structures_[l,r]/bit.hpp b/library/data_structures_[l,r]/bit.hpp index e720d7ce..1c96c37f 100644 --- a/library/data_structures_[l,r]/bit.hpp +++ b/library/data_structures_[l,r]/bit.hpp @@ -1,10 +1,7 @@ #pragma once //! @code //! BIT bit(n); -//! bit.walk([&](int r, int64_t sum) -> bool { -//! // sum = a[0] + a[1] + ... + a[r] -//! }); -//! int r = bit.walk2(sum); +//! int r = bit.walk(sum); //! // Returns min r s.t. sum of [0,r] >= sum //! // Returns n if sum of [0,n-1] < sum //! // Returns -1 if sum <= 0 @@ -27,6 +24,5 @@ struct BIT { ll query(int l, int r) { return query(r) - query(l - 1); } -#include "bit_uncommon/walk_lambda.hpp" #include "../data_structures_[l,r)/bit_uncommon/walk.hpp" }; diff --git a/library/data_structures_[l,r]/bit_uncommon/walk_lambda.hpp b/library/data_structures_[l,r]/bit_uncommon/walk_lambda.hpp deleted file mode 100644 index 1f456b64..00000000 --- a/library/data_structures_[l,r]/bit_uncommon/walk_lambda.hpp +++ /dev/null @@ -1,6 +0,0 @@ -void walk(auto f) { - ll sum = 0; - for (int i = bit_floor(size(s)), r = 0; i; i /= 2) - if (r + i <= sz(s) && f(r + i - 1, sum + s[r + i - 1])) - sum += s[(r += i) - 1]; -} diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index 8a142f3b..49d1b2cf 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -60,5 +60,5 @@ unusedFunction:../kactl/content/data-structures/UnionFind.h:14 unusedFunction:../kactl/content/number-theory/ModPow.h:13 unusedFunction:../kactl/stress-tests/utilities/genTree.h:49 containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85 -ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:15 +ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:12 ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4 diff --git a/tests/library_checker_aizu_tests/data_structures/bit.test.cpp b/tests/library_checker_aizu_tests/data_structures/bit.test.cpp index 987d9400..32d1713c 100644 --- a/tests/library_checker_aizu_tests/data_structures/bit.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/bit.test.cpp @@ -58,7 +58,7 @@ int main() { } return 1; }; - assert(bit.walk2(sum) == st.find_first(0, n, f)); + assert(bit.walk(sum) == st.find_first(0, n, f)); } return 0; } diff --git a/tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp b/tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp index 71709b07..4d072cca 100644 --- a/tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp @@ -23,27 +23,13 @@ int main() { if (bit.query(k, n - 1) == 0) cout << -1 << '\n'; else { ll order = bit.query(k - 1); - int res = -1; - bit.walk([&](int r, ll sum) { - if (sum <= order) return 1; - res = r; - return 0; - }); - cout << res << '\n'; + cout << bit.walk(order + 1) << '\n'; } } else { if (bit.query(k) == 0) cout << -1 << '\n'; else { ll order = bit.query(k); - int res = -1; - bit.walk([&](int r, ll sum) { - if (sum >= order) { - res = r; - return 0; - } - return 1; - }); - cout << res << '\n'; + cout << bit.walk(order) << '\n'; } } } diff --git a/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp b/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp index 009a8353..cf43717e 100644 --- a/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp @@ -40,7 +40,7 @@ int main() { x = get_compressed_idx(x); if (bit.query(x, x) == 1) bit.update(x, -1); } else if (type == 2) { - int res = bit.walk2(x); + int res = bit.walk(x); if (res == -1 || res == sz(compress)) cout << -1 << '\n'; else cout << compress[res] << '\n'; @@ -49,12 +49,12 @@ int main() { cout << bit.query(x) << '\n'; } else if (type == 4) { x = get_compressed_idx(x); - int res = bit.walk2(bit.query(x)); + int res = bit.walk(bit.query(x)); if (res == -1) cout << -1 << '\n'; else cout << compress[res] << '\n'; } else { x = get_compressed_idx(x); - int res = bit.walk2(bit.query(x - 1) + 1); + int res = bit.walk(bit.query(x - 1) + 1); if (res == sz(bit.s)) cout << -1 << '\n'; else cout << compress[res] << '\n'; } diff --git a/tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp b/tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp index 9ea8ac99..dec7c764 100644 --- a/tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp @@ -46,22 +46,13 @@ int main() { } return 1; }; - int res = bit.walk2(order + 1); + int res = bit.walk(order + 1); assert(res == st.find_first(0, n, f)); assert(res == st.find_first(k, n, [&](ll x, int, int) -> bool { return x > 0; })); if (res == n) res = -1; - int res_lambda = -1; - bit.walk([&](int r, ll sum) { - if (sum > order) { - res_lambda = r - 1; - return 0; - } - return 1; - }); - assert(res == res_lambda); cout << res << '\n'; } else { if (bit.query(k, k + 1) == 1) { @@ -78,24 +69,12 @@ int main() { } return 1; }; - int res = bit.walk2(order); + int res = bit.walk(order); assert(max(res, 0) == st.find_first(0, n, f)); assert(res == st.find_last(0, k + 1, [&](ll x, int, int) -> bool { return x > 0; })); - int res_lambda = -1; - if (order) { - bit.walk([&](int r, ll sum) { - if (sum < order) { - res_lambda = r; - return 1; - } - res_lambda = r - 1; - return 0; - }); - } - assert(res == res_lambda); cout << res << '\n'; } } diff --git a/tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp b/tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp index b60ad939..67eec1ce 100644 --- a/tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp +++ b/tests/library_checker_aizu_tests/handmade_tests/seg_tree_find.test.cpp @@ -37,7 +37,7 @@ int main() { rngs.push_back({tl, tr, 1}); return 1; }; - int pos = min(bit.walk2(bit.query(l) + sum), r); + int pos = min(bit.walk(bit.query(l) + sum), r); reset(); assert(pos == seg.find_first(l, r, f)); assert(!empty(rngs));