Skip to content

Commit 3cd68d8

Browse files
authored
Change wavelet_matrix constructor parameter to const reference
Refactor wavelet_matrix constructor to accept a const reference for the input vector.
1 parent 6f3a198 commit 3cd68d8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
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--;) {
17-
int i = 0;
1819
vector<bool> b(n);
19-
ranges::stable_partition(a,
20-
[&](ull x) { return b[i++] = (~x >> h) & 1; });
20+
ranges::stable_partition(idx,
21+
[&](int i) { return b[i] = (~a[i] >> h) & 1; });
2122
bv[h] = b;
2223
}
2324
}

0 commit comments

Comments
 (0)