Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 5 deletions library/data_structures_[l,r)/bit.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
};
2 changes: 1 addition & 1 deletion library/data_structures_[l,r)/bit_uncommon/walk.hpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 0 additions & 6 deletions library/data_structures_[l,r)/bit_uncommon/walk_lambda.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions library/data_structures_[l,r]/bit.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
};
6 changes: 0 additions & 6 deletions library/data_structures_[l,r]/bit_uncommon/walk_lambda.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion tests/.config/.cppcheck_suppression_list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
}
Expand Down
25 changes: 2 additions & 23 deletions tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading