This documentation is automatically generated by online-judge-tools/verification-helper
各要素が $0$ もしくは $1$ に限定される配列の構築を $O(n)$、区間和を $O(1)$ で行えるデータ構造。通常の累積和よりも省メモリである。
BitVector(n: int)
長さが $n$ で全要素が $0$ であるビットベクトルを構築する。計算量 $O(n)$
set(i: int) -> None
$i$ 番目の要素を $1$ に更新する。計算量 $O(1)$
access(i) -> int
$i$ 番目の値を返す。計算量 $O(1)$
build() -> None
ビットベクトルに対する累積和を構築する。計算量 $O(n)$
rank(r: int, f: bool) -> int
$[0, r)$ 番目について、f = True
のとき $1$ の個数を、f = False
のとき $0$ の個数を返す。計算量 $O(1)$
class BitVector:
def __init__(self, n):
# self.BLOCK_WIDTH = 32
self.BLOCK_NUM = (n + 31) >> 5
self.bit = [0] * self.BLOCK_NUM
self.count = [0] * self.BLOCK_NUM
def _popcount(self, x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0F0F0F0F
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007F
def set(self, i):
self.bit[i >> 5] |= 1 << (i & 31)
def access(self, i):
return (self.bit[i >> 5] >> (i & 31)) & 1
def build(self):
for i in range(self.BLOCK_NUM - 1):
self.count[i + 1] = self.count[i] + self._popcount(self.bit[i])
def rank(self, r, f):
res = self.count[r >> 5] + self._popcount(self.bit[r >> 5] & ((1 << (r & 31)) - 1))
return res if f else r - res
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
raise NotImplementedError
NotImplementedError