Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshihiro Shimizu authored and Toshihiro Shimizu committed Dec 8, 2024
1 parent f33be7c commit fd885db
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/atcoder/extra/math/combination_table.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ when not defined ATCODER_COMBINATION_HPP:
x is typedesc[RingElem] or x is var Combination

proc getAddr(T:typedesc[RingElem]):auto {.discardable.} =
var cmb_a{.global.} = Combination[T]()
var cmb_a{.global.}:Combination[T]
once:
cmb_a = Combination[T]()
return cmb_a.addr

template zero*(T:typedesc[RingElem]):T = T(0)
Expand Down
5 changes: 4 additions & 1 deletion src/atcoder/extra/math/modint_montgomery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ when not declared ATCODER_MONTGOMERY_MODINT_HPP:
(M, get_r(M), get_n2(M))

proc getParameters*[T:static[int]](t:typedesc[DynamicLazyMontgomeryModInt[T]]):ptr[tuple[M, r, n2:uint32]] =
var p {.global.} : tuple[M, r, n2:uint32] = getMontgomeryParameters(998244353.uint32)
{.cast(noSideEffect).}:
var p {.global.} : tuple[M, r, n2:uint32]
once:
p = getMontgomeryParameters(998244353.uint32)
return p.addr

proc checkParameters(M, r:uint32) =
Expand Down
2 changes: 1 addition & 1 deletion src/atcoder/extra/tree/rerooting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ when not declared ATCODER_REROOTING_HPP:
if self.G[v][i].dst == p:
self.dp[v][i] = from_par
break
var pR = newSeq[T, Weight](self.G[v].len + 1)
var pR = newSeq[T](self.G[v].len + 1)
pR[self.G[v].len] = self.mi
for i in countdown(self.G[v].len, 1):
let e = self.G[v][i - 1]
Expand Down
2 changes: 1 addition & 1 deletion src/atcoder/lazysegtree.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ when not declared ATCODER_LAZYSEGTREE_HPP:
proc init*[ST:LazySegTree](self: var ST, n:int) = self.init(newSeqWith(n, ST.calc_e()))
proc init*[ST:LazySegTree](self: typedesc[ST], v:seq[ST.S] or int):ST = result.init(v)

template LazySegTreeType[S, F](op0, e0, mapping0, composition0, id0:untyped):typedesc[LazySegTree] =
template LazySegTreeType*[S, F](op0, e0, mapping0, composition0, id0:untyped):typedesc[LazySegTree] =
proc op1(a, b:S):S {.gensym inline.} = op0(a, b)
proc e1():S {.gensym inline.} = e0()
proc mapping1(f:F, s:S):S {.gensym inline.} = mapping0(f, s)
Expand Down
4 changes: 3 additions & 1 deletion src/atcoder/modint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ when not declared ATCODER_MODINT_HPP:

proc getBarrett*[T:static[int]](t:typedesc[DynamicModInt[T]]):ptr Barrett =
{.cast(noSideEffect).}:
var Barrett_of_DynamicModInt {.global.} = initBarrett(998244353.uint)
var Barrett_of_DynamicModInt {.global.}: Barrett
once:
Barrett_of_DynamicModInt = initBarrett(998244353.uint)
return Barrett_of_DynamicModInt.addr

proc getMod*[T:static[int]](t:typedesc[DynamicModInt[T]]):uint32 {.inline.} =
Expand Down
5 changes: 4 additions & 1 deletion src/atcoder/modint_backup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ when not declared ATCODER_MODINT_HPP:
import atcoder/internal_math

proc getBarrett*[T:static[int]](t:typedesc[DynamicModInt[T]], set = false, M:SomeInteger = 0.uint32):ptr Barrett =
var Barrett_of_DynamicModInt {.global.} = initBarrett(998244353.uint)
{.cast(noSideEffect).}:
var Barrett_of_DynamicModInt {.global.}: Barrett
once:
Barrett_of_DynamicModInt = initBarrett(998244353.uint)
return Barrett_of_DynamicModInt.addr
proc getMod*[T:static[int]](t:typedesc[DynamicModInt[T]]):uint32 {.inline.} =
(t.getBarrett)[].m.uint32
Expand Down

0 comments on commit fd885db

Please sign in to comment.