Neterukun's Library

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

View the Project on GitHub Neterukun1993/Library

:heavy_check_mark: いもす法
(DataStructure/AccumulateSum/Imos.py)

使い方

Imos(n: int)
大きさ $n$ のいもす法用の配列を初期構築する。計算量 $O(n)$
その後の一連の処理としては

  1. add 関数で区間加算の準備をする。
  2. build 関数で区間加算を実行する。
  3. __getitem__ 関数で値を取得する。

となる。

参考

いもす法 - いもす研 (imos laboratory)

Verified with

Code

class Imos:
    def __init__(self, n):
        self.n = n
        self.imos = [0] * (self.n + 1)

    def __getitem__(self, i):
        return self.imos[i]

    def add(self, l, r, val):
        """add value in range [l, r)"""
        self.imos[r] -= val
        self.imos[l] += val

    def build(self):
        for i in range(self.n):
            self.imos[i + 1] += self.imos[i]
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