We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cede36a commit 40cd17aCopy full SHA for 40cd17a
library/data_structures/seg_tree_uncommon/wavelet_bit_vec.hpp
@@ -10,13 +10,14 @@ using ull = uint64_t;
10
struct bit_vec {
11
vector<pair<ull, int>> b;
12
bit_vec(const vector<bool>& a): b(sz(a) / 64 + 1) {
13
- rep(i, 0, sz(a)) b[i >> 6].first |= ull(a[i])
14
- << (i & 63);
15
- rep(i, 0, sz(b) - 1) b[i + 1].second =
16
- popcount(b[i].first) + b[i].second;
+ rep(i, 0, sz(a)) {
+ auto& [x, y] = b[i >> 6];
+ x |= ull(a[i]) << (i & 63), y += a[i];
+ }
17
+ rep(i, 1, sz(b)) b[i].second += b[i - 1].second;
18
}
19
int cnt(int r) {
20
auto [x, y] = b[r >> 6];
- return y + popcount(x & ((1ULL << (r & 63)) - 1));
21
+ return y - popcount(x & -1ULL << (r & 63));
22
23
};
0 commit comments