We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d8f6769 commit cd5257cCopy full SHA for cd5257c
library/data_structures_[l,r)/seg_tree_uncommon/wavelet_matrix.hpp
@@ -11,13 +11,15 @@
11
struct wavelet_matrix {
12
int n;
13
vector<bit_vec> bv;
14
- wavelet_matrix(vector<ull> a, ull max_val):
+ wavelet_matrix(const vector<ull>& a, ull max_val):
15
n(sz(a)), bv(bit_width(max_val), {{}}) {
16
+ vi idx(n);
17
+ iota(all(idx), 0);
18
for (int h = sz(bv); h--;) {
19
vector<bool> b(n);
- rep(i, 0, n) b[i] = (~a[i] >> h) & 1;
- ranges::stable_partition(a,
20
- [&](ull x) { return (~x >> h) & 1; });
+ rep(i, 0, n) b[i] = (~a[idx[i]] >> h) & 1;
21
+ ranges::stable_partition(idx,
22
+ [&](int i) { return b[i]; });
23
bv[h] = b;
24
}
25
0 commit comments