File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
library/data_structures/seg_tree_uncommon Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 11#pragma once
2+ // ! @code
3+ // ! vector<bool> a(n);
4+ // ! bit_vec bv(a);
5+ // ! bv.cnt(r); // a[0] + a[1] + ... + a[r - 1]
6+ // ! @endcode
7+ // ! @time O(n + q)
8+ // ! @space O(n / 64)
29#define ull uint64_t
310struct bit_vec {
411 vector<pair<ull, int >> b;
5- // ! @time O(n)
6- // ! @space O(n / 64)
712 bit_vec (const vector<bool >& a): b(sz(a) / 64 + 1 ) {
813 rep (i, 0 , sz (a)) b[i >> 6 ].first |= ull (a[i])
914 << (i & 63 );
1015 rep (i, 0 , sz (b) - 1 ) b[i + 1 ].second =
1116 popcount (b[i].first ) + b[i].second ;
1217 }
13- // ! @returns a[0] + a[1] + ... + a[r - 1]
14- // ! @time O(1)
15- // ! @space O(1)
1618 int cnt (int r) {
1719 auto [x, y] = b[r >> 6 ];
1820 return y + popcount (x & ((1ULL << (r & 63 )) - 1 ));
You can’t perform that action at this time.
0 commit comments