Skip to content

Commit cd5257c

Browse files
authored
Update wavelet_matrix.hpp
1 parent d8f6769 commit cd5257c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

library/data_structures_[l,r)/seg_tree_uncommon/wavelet_matrix.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
struct wavelet_matrix {
1212
int n;
1313
vector<bit_vec> bv;
14-
wavelet_matrix(vector<ull> a, ull max_val):
14+
wavelet_matrix(const vector<ull>& a, ull max_val):
1515
n(sz(a)), bv(bit_width(max_val), {{}}) {
16+
vi idx(n);
17+
iota(all(idx), 0);
1618
for (int h = sz(bv); h--;) {
1719
vector<bool> b(n);
18-
rep(i, 0, n) b[i] = (~a[i] >> h) & 1;
19-
ranges::stable_partition(a,
20-
[&](ull x) { return (~x >> h) & 1; });
20+
rep(i, 0, n) b[i] = (~a[idx[i]] >> h) & 1;
21+
ranges::stable_partition(idx,
22+
[&](int i) { return b[i]; });
2123
bv[h] = b;
2224
}
2325
}

0 commit comments

Comments
 (0)