Neterukun's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Neterukun1993/Library

:heavy_check_mark: Radix Heap
(DataStructure/Heap/RadixHeap.py)

使い方

RadixHeap(LIMIT: int)
格納可能な最大値 LIMIT を指定した空のヒープを作成する。計算量 $O(\log \mathrm{LIMIT})$

Required by

Verified with

Code

class RadixHeap:
    def __init__(self, LIMIT):
        self.LIMIT = LIMIT
        self.vals = [[] for i in range(LIMIT.bit_length() + 1)]
        self.size = 0
        self.last = 0

    def __len__(self):
        return self.size

    def push(self, key, val):
        if key > self.LIMIT:
            raise RuntimeError(f'A pushed value {x} must be no more than {self.LIMIT}')
        if self.last > key:
            raise RuntimeError(f'A pushed value {x} must be not less than the last poped value')
        self.size += 1
        self.vals[(key ^ self.last).bit_length()].append((key, val))

    def pop(self):
        if self.size == 0:
            raise IndexError('pop from empty heapq')
        if not self.vals[0]:
            i = 1
            while not self.vals[i]:
                i += 1
            self.last = min([key for key, _ in self.vals[i]])
            for key, val in self.vals[i]:
                self.vals[(key ^ self.last).bit_length()].append((key, val))
            self.vals[i] = []
        self.size -= 1
        return self.vals[0].pop()
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
Back to top page