A complete MoonBit port of AtCoder Library v1.6
| ACL | MoonBit の公開 API |
|---|---|
| dsu | Dsu |
| fenwicktree | FenwickTree[T] |
| segtree | SegTree[S] |
| lazysegtree | LazySegTree[S, F] |
| math | pow_mod, inv_mod, crt, floor_sum |
| modint | StaticModInt[M], DynamicModInt[Id]、定番の型エイリアス |
| convolution | convolution, convolution_modint, convolution_ll |
| maxflow | MfGraph[Cap], MfEdge[Cap] |
| mincostflow | McfGraph[Cap, Cost], McfEdge[Cap, Cost] |
| scc | SccGraph |
| twosat | TwoSat |
| string | suffix array / LCP / Z:配列・Bytes・String |
python3 scripts/setup.py
scripts/moon test --target all
scripts/check.shmoon add manabeai/ac-library-mbt@0.1.0// moon.work(両モジュールの親ディレクトリ)
members = [ "ac-library-mbt", "solution" ]// solution/moon.mod
name = "local/solution"
import { "manabeai/ac-library-mbt@0.1.0" }// solution/moon.pkg(または source 配下の moon.pkg)
import { "manabeai/ac-library-mbt" @ac }import { "manabeai/ac-library-mbt/segtree" @segtree }let fw : @ac.FenwickTree[Int64] = @ac.FenwickTree::new(5)
fw.add(2, 10L)
assert_eq(fw.sum(1, 4), 10L)
let seg = @ac.SegTree::from_array(
[1, 3, 2, 5],
op=Int::max,
e=() => -1,
)
assert_eq(seg.prod(1, 3), 3)
assert_eq(seg.max_right(0, maximum => maximum < 5), 3)let tree : @ac.LazySegTree[(Int64, Int), (Int64, Int64)] =
@ac.LazySegTree::from_array(
[(1L, 1), (2L, 1), (3L, 1)],
op=(a, b) => (a.0 + b.0, a.1 + b.1),
e=() => (0L, 0),
mapping=(f, x) => (f.0 * x.0 + f.1 * x.1.to_int64(), x.1),
composition=(f, g) => (f.0 * g.0, f.0 * g.1 + f.1),
id=() => (1L, 0L),
)
tree.apply_range(0, 2, (2L, 1L))
assert_eq(tree.prod(0, 3).0, 11L)let a : @ac.ModInt998244353 = @ac.StaticModInt::new(10)
let b : @ac.ModInt998244353 = @ac.StaticModInt::new(3)
assert_eq((a / b * b).val(), 10)
assert_eq(a.pow(3L).val(), 1000)
@ac.set_mod(11)
let x : @ac.ModInt = @ac.DynamicModInt::new(15)
assert_eq(x.val(), 4)
assert_eq(x.mod(), 11)assert_eq(@ac.convolution([1L, 2L], [3L, 4L]), [3L, 10L, 8L])
assert_eq(@ac.convolution_ll([-1L, 2L], [3L, -4L]), [-3L, 10L, -8L])
assert_eq(@ac.suffix_array_string("banana"), [5, 3, 1, 0, 4, 2])fn[M : Modulus] convolution_modint(a : Array[StaticModInt[M]], b : Array[StaticModInt[M]]) -> Array[StaticModInt[M]]fn floor_sum(n : Int64, m : Int64, a : Int64, b : Int64) -> Int64fn inv_mod(x : Int64, m : Int64) -> Int64fn pow_mod(x : Int64, n : Int64, m : Int) -> Int64fn set_mod(modulus : Int) -> UnitInstall
Download zipA complete MoonBit port of AtCoder Library v1.6