verify/AI/dualsegtree_static_op_test.nim

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

:heavy_check_mark: verify/AI/dualsegtree_static_op_test.nim

Depends on

Code

# verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A
echo "Hello World"

import cplib/collections/dualsegtree_static_op

type Affine = tuple[a, b: int]

var seg = newDualSegWith(
    @[1, 2, 3, 4, 5],
    f.a * x + f.b,
    (a: f.a * g.a, b: f.a * g.b + f.b),
    (a: 1, b: 0)
)
assert seg.len == 5
seg.apply(0, 5, (a: 2, b: 1))
seg.apply(1, 4, (a: 3, b: -2))
assert seg.toSeq == @[3, 13, 19, 25, 11]
seg.apply(2..4, (a: 1, b: 10))
assert seg[2] == 29
assert seg[^1] == 21
seg[3] = 100
assert seg.toSeq == @[3, 13, 29, 100, 21]
assert $seg == "3 13 29 100 21"

var bySize = newDualSegWith(
    4,
    5,
    f.a * x + f.b,
    (a: f.a * g.a, b: f.a * g.b + f.b),
    (a: 1, b: 0)
)
bySize.apply(1, 4, (a: 2, b: 0))
assert bySize.toSeq == @[5, 10, 10, 10]

var initializedWithProc = initDualSegmentTree(
    @[1, 2, 3],
    proc(f: Affine, x: int): int = f.a * x + f.b,
    proc(f, g: Affine): Affine = (f.a * g.a, f.a * g.b + f.b),
    (a: 1, b: 0)
)
initializedWithProc.apply(0, 3, (a: 2, b: 1))
assert initializedWithProc.toSeq == @[3, 5, 7]

var empty = initDualSegmentTree(
    newSeq[int](),
    proc(f: Affine, x: int): int = f.a * x + f.b,
    proc(f, g: Affine): Affine = (f.a * g.a, f.a * g.b + f.b),
    (a: 1, b: 0)
)
empty.apply(0, 0, (a: 2, b: 3))
assert empty.len == 0
assert empty.toSeq == newSeq[int]()
Traceback (most recent call last):
  File "/home/runner/.local/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 "/home/runner/.local/lib/python3.12/site-packages/onlinejudge_verify/languages/nim.py", line 86, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page