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/Imos2D.py)

使い方

Imos2D(h: int, w: int)
大きさ $h × w$ のいもす法用の二次元配列を初期構築する。計算量 $O(hw)$
その後の一連の処理としては

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

となる。

参考

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

Verified with

Code

class Imos2D:
    def __init__(self, h, w):
        self.h = h
        self.w = w
        self.imos = [[0] * (self.w + 1) for _ in range(self.h + 1)]

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

    def add(self, hl, hr, wl, wr, val):
        """add value in range [hl, hr) * [wl, wr)"""
        self.imos[hl][wl] += val
        self.imos[hr][wl] -= val
        self.imos[hl][wr] -= val
        self.imos[hr][wr] += val

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