Skip to content

Commit 53332cc

Browse files
committed
fix this test
1 parent cbf3416 commit 53332cc

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,41 @@ int main() {
1919
ranges::sort(compress);
2020
compress.erase(unique(all(compress)), end(compress));
2121
bit_inc bit(ssize(compress));
22+
auto get_compressed_idx = [&](int val) -> int {
23+
int l = 0, r = ssize(compress);
24+
while (l + 1 < r) {
25+
int m = (l + r) / 2;
26+
if (compress[m] <= val) l = m;
27+
else r = m;
28+
}
29+
return l;
30+
};
2231
for (int i = 0; i < n; i++) {
23-
int val = ranges::lower_bound(compress, init[i]) -
24-
begin(compress);
32+
int val = get_compressed_idx(init[i]);
2533
bit.update(val, 1);
2634
}
2735
for (auto [type, x] : query) {
2836
if (type == 0) {
29-
x =
30-
ranges::lower_bound(compress, x) - begin(compress);
37+
x = get_compressed_idx(x);
3138
if (bit.query(x, x) == 0) bit.update(x, 1);
3239
} else if (type == 1) {
33-
x =
34-
ranges::lower_bound(compress, x) - begin(compress);
40+
x = get_compressed_idx(x);
3541
if (bit.query(x, x) == 1) bit.update(x, -1);
3642
} else if (type == 2) {
3743
int res = bit.walk(x);
3844
if (res == -1 || res == ssize(compress))
3945
cout << -1 << '\n';
4046
else cout << compress[res] << '\n';
4147
} else if (type == 3) {
42-
x =
43-
ranges::lower_bound(compress, x) - begin(compress);
48+
x = get_compressed_idx(x);
4449
cout << bit.query(x) << '\n';
4550
} else if (type == 4) {
46-
x =
47-
ranges::lower_bound(compress, x) - begin(compress);
51+
x = get_compressed_idx(x);
4852
int res = bit.prev(x);
4953
if (res == -1) cout << -1 << '\n';
5054
else cout << compress[res] << '\n';
5155
} else {
52-
x =
53-
ranges::lower_bound(compress, x) - begin(compress);
56+
x = get_compressed_idx(x);
5457
int res = bit.next(x);
5558
if (res == ssize(bit.s)) cout << -1 << '\n';
5659
else cout << compress[res] << '\n';

0 commit comments

Comments
 (0)