Safe Haskell | None |
---|---|
Language | GHC2021 |
SegAct
instance of one-dimensional affine transformation
\(f: x \rightarrow a \times x + b\).
Since: 1.0.0
Synopsis
- newtype Affine1 a = Affine1 (Affine1Repr a)
- type Affine1Repr a = (a, a)
- new :: a -> a -> Affine1 a
- act :: Num a => Affine1 a -> a -> a
Affine1
SegAct
instance of one-dimensional affine transformation
\(f: x \rightarrow a \times x + b\).
Composition and dual
Semigroup
for Affine1
is implemented like function composition, and rightmost affine
transformation is applied first: \((f_1 \circ f_2) v := f_1 (f_2(v))\). If you need foldr
of \([f_l, f_{l+1}, .., f_r)\) on a segment tree, be sure to wrap Affine1
in
Dual
.
Example
>>>
import AtCoder.Extra.Monoid (SegAct(..), Affine1(..))
>>>
import AtCoder.LazySegTree qualified as LST
>>>
seg <- LST.build @_ @(Affine1 Int) @(Sum Int) $ VU.generate 3 Sum -- [0, 1, 2]
>>>
LST.applyIn seg 0 3 $ Affine1 (2, 1) -- [1, 3, 5]
>>>
getSum <$> LST.allProd seg
9
Since: 1.0.0
Affine1 (Affine1Repr a) |
Instances
type Affine1Repr a = (a, a) #