ac-library-hs-0.1.0.0: Data structures and algorithms
Safe HaskellNone
LanguageGHC2021

AtCoder.Extra.Monoid

Description

Extra module of pre-defined SegAct instances.

Be warned that they're not 100% guaranteed to be correct.

Since: 1.0.0

Synopsis

SegAct (re-export)

class Monoid f => SegAct f a where #

Typeclass reprentation of the LazySegTree properties. User can implement either segAct or segActWithLength.

Instances should satisfy the follwing:

Left monoid action
segAct (f2 <> f1) x = segAct f2 (segAct f1 x)
Identity map
segAct mempty x = x
Endomorphism
segAct f (x1 <> x2) = (segAct f x1) <> (segAct f x2)

If you implement segActWithLength, satisfy one more propety:

Linear left monoid action
segActWithLength len f a = stimes len (segAct f a) a.

Note that in SegAct instances, new semigroup values are always given from the left: new <> old.

Example instance

Expand

Take Affine1 as an example of type \(F\).

{-# LANGUAGE TypeFamilies #-}

import AtCoder.LazySegTree qualified as LST
import AtCoder.LazySegTree (SegAct (..))
import Data.Monoid
import Data.Vector.Generic qualified as VG
import Data.Vector.Generic.Mutable qualified as VGM
import Data.Vector.Unboxed qualified as VU
import Data.Vector.Unboxed.Mutable qualified as VUM

-- | f x = a * x + b. It's implemented as a newtype of `(a, a)` for easy Unbox deriving.
newtype Affine1 a = Affine1 (Affine1 a)
  deriving newtype (Eq, Ord, Show)

-- | This type alias makes the Unbox deriving easier, described velow.
type Affine1Repr a = (a, a)

instance (Num a) => Semigroup (Affine1 a) where
  {-# INLINE (<>) #-}
  (Affine1 (!a1, !b1)) <> (Affine1 (!a2, !b2)) = Affine1 (a1 * a2, a1 * b2 + b1)

instance (Num a) => Monoid (Affine1 a) where
  {-# INLINE mempty #-}
  mempty = Affine1 (1, 0)

instance (Num a) => SegAct (Affine1 a) (Sum a) where
  {-# INLINE segActWithLength #-}
  segActWithLength len (Affine1 (!a, !b)) !x = a * x + b * fromIntegral len

Deriving Unbox is very easy for such a newtype (though the efficiency is not the maximum):

newtype instance VU.MVector s (Affine1 a) = MV_Affine1 (VU.MVector s (Affine1 a))
newtype instance VU.Vector (Affine1 a) = V_Affine1 (VU.Vector (Affine1 a))
deriving instance (VU.Unbox a) => VGM.MVector VUM.MVector (Affine1 a)
deriving instance (VU.Unbox a) => VG.Vector VU.Vector (Affine1 a)
instance (VU.Unbox a) => VU.Unbox (Affine1 a)

Example contest template

Expand

Define your monoid action F and your acted monoid X:

{-# LANGUAGE TypeFamilies #-}

import AtCoder.LazySegTree qualified as LST
import AtCoder.LazySegTree (SegAct (..))
import Data.Vector.Generic qualified as VG
import Data.Vector.Generic.Mutable qualified as VGM
import Data.Vector.Unboxed qualified as VU
import Data.Vector.Unboxed.Mutable qualified as VUM

{- ORMOLU_DISABLE -}
-- | F is a custom monoid action, defined as a newtype of FRepr.
newtype F = F FRepr deriving newtype (Eq, Ord, Show) ; unF :: F -> FRepr ; unF (F x) = x ; newtype instance VU.MVector s F = MV_F (VU.MVector s FRepr) ; newtype instance VU.Vector F = V_F (VU.Vector FRepr) ; deriving instance VGM.MVector VUM.MVector F ; deriving instance VG.Vector VU.Vector F ; instance VU.Unbox F ;
{- ORMOLU_ENABLE -}

-- | Affine: f x = a * x + b
type FRepr = (Int, Int)

instance Semigroup F where
  -- new <> old
  {-# INLINE (<>) #-}
  (F (!a1, !b1)) <> (F (!a2, !b2)) = F (a1 * a2, a1 * b2 + b1)

instance Monoid F where
  {-# INLINE mempty #-}
  mempty = F (1, 0)

{- ORMOLU_DISABLE -}
-- | X is a custom acted monoid, defined as a newtype of XRepr.
newtype X = X XRepr deriving newtype (Eq, Ord, Show) ; unX :: X -> XRepr ; unX (X x) = x; newtype instance VU.MVector s X = MV_X (VU.MVector s XRepr) ; newtype instance VU.Vector X = V_X (VU.Vector XRepr) ; deriving instance VGM.MVector VUM.MVector X ; deriving instance VG.Vector VU.Vector X ; instance VU.Unbox X ;
{- ORMOLU_ENABLE -}

-- | Acted Int (same as `Sum Int`).
type XRepr = Int

deriving instance Num X; -- in our case X is a Num.

instance Semigroup X where
  {-# INLINE (<>) #-}
  (X x1) <> (X x2) = X $! x1 + x2

instance Monoid X where
  {-# INLINE mempty #-}
  mempty = X 0

instance SegAct F X where
  -- {-# INLINE segAct #-}
  -- segAct len (F (!a, !b)) (X x) = X $! a * x + b
  {-# INLINE segActWithLength #-}
  segActWithLength len (F (!a, !b)) (X x) = X $! a * x + len * b

It's tested as below:

expect :: (Eq a, Show a) => String -> a -> a -> ()
expect msg a b
  | a == b = ()
  | otherwise = error $ msg ++ ": expected " ++ show a ++ ", found " ++ show b

main :: IO ()
main = do
  seg <- LST.build _ F @X $ VU.map X $ VU.fromList [1, 2, 3, 4]
  LST.applyIn seg 1 3 $ F (2, 1) -- [1, 5, 7, 4]
  LST.write seg 3 $ X 10 -- [1, 5, 7, 10]
  LST.modify seg (+ (X 1)) 0   -- [2, 5, 7, 10]
  !_ <- (expect "test 1" (X 5)) <$> LST.read seg 1
  !_ <- (expect "test 2" (X 14)) <$> LST.prod seg 0 3 -- reads an interval [0, 3)
  !_ <- (expect "test 3" (X 24)) <$> LST.allProd seg
  !_ <- (expect "test 4" 2) <$> LST.maxRight seg 0 (<= (X 10)) -- sum [0, 2) = 7 <= 10
  !_ <- (expect "test 5" 3) <$> LST.minLeft seg 4 (<= (X 10)) -- sum [3, 4) = 10 <= 10
  putStrLn "=> test passed!"

Since: 1.0.0

Minimal complete definition

Nothing

Methods

segAct :: f -> a -> a #

Lazy segment tree action \(f(x)\).

Since: 1.0.0

segActWithLength :: Int -> f -> a -> a #

Lazy segment tree action \(f(x)\) with the target monoid's length.

If you implement SegAct with this function, you don't have to store the monoid's length, since it's given externally.

Since: 1.0.0

Instances

Instances details
Monoid a => SegAct (RangeSet a) a #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

segAct :: RangeSet a -> a -> a #

segActWithLength :: Int -> RangeSet a -> a -> a #

Num a => SegAct (Affine1 (Sum a)) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Affine1 (Sum a) -> Sum a -> Sum a #

segActWithLength :: Int -> Affine1 (Sum a) -> Sum a -> Sum a #

Num a => SegAct (Affine1 a) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Affine1 a -> Sum a -> Sum a #

segActWithLength :: Int -> Affine1 a -> Sum a -> Sum a #

Num a => SegAct (RangeAdd a) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

segAct :: RangeAdd a -> Sum a -> Sum a #

segActWithLength :: Int -> RangeAdd a -> Sum a -> Sum a #

Num a => SegAct (RangeAddId a) (Max a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Methods

segAct :: RangeAddId a -> Max a -> Max a #

segActWithLength :: Int -> RangeAddId a -> Max a -> Max a #

Num a => SegAct (RangeAddId a) (Min a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Methods

segAct :: RangeAddId a -> Min a -> Min a #

segActWithLength :: Int -> RangeAddId a -> Min a -> Min a #

(Ord a, Bounded a) => SegAct (RangeSetId (Max a)) (Max a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Methods

segAct :: RangeSetId (Max a) -> Max a -> Max a #

segActWithLength :: Int -> RangeSetId (Max a) -> Max a -> Max a #

(Ord a, Bounded a) => SegAct (RangeSetId (Min a)) (Min a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Methods

segAct :: RangeSetId (Min a) -> Min a -> Min a #

segActWithLength :: Int -> RangeSetId (Min a) -> Min a -> Min a #

Num a => SegAct (Dual (Affine1 (Sum a))) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Dual (Affine1 (Sum a)) -> Sum a -> Sum a #

segActWithLength :: Int -> Dual (Affine1 (Sum a)) -> Sum a -> Sum a #

Num a => SegAct (Dual (Affine1 a)) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Dual (Affine1 a) -> Sum a -> Sum a #

segActWithLength :: Int -> Dual (Affine1 a) -> Sum a -> Sum a #

Affine1

newtype Affine1 a #

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

Constructors

Affine1 (Affine1Repr a) 

Instances

Instances details
Unbox a => Vector Vector (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Unbox a => MVector MVector (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

basicLength :: MVector s (Affine1 a) -> Int #

basicUnsafeSlice :: Int -> Int -> MVector s (Affine1 a) -> MVector s (Affine1 a) #

basicOverlaps :: MVector s (Affine1 a) -> MVector s (Affine1 a) -> Bool #

basicUnsafeNew :: Int -> ST s (MVector s (Affine1 a)) #

basicInitialize :: MVector s (Affine1 a) -> ST s () #

basicUnsafeReplicate :: Int -> Affine1 a -> ST s (MVector s (Affine1 a)) #

basicUnsafeRead :: MVector s (Affine1 a) -> Int -> ST s (Affine1 a) #

basicUnsafeWrite :: MVector s (Affine1 a) -> Int -> Affine1 a -> ST s () #

basicClear :: MVector s (Affine1 a) -> ST s () #

basicSet :: MVector s (Affine1 a) -> Affine1 a -> ST s () #

basicUnsafeCopy :: MVector s (Affine1 a) -> MVector s (Affine1 a) -> ST s () #

basicUnsafeMove :: MVector s (Affine1 a) -> MVector s (Affine1 a) -> ST s () #

basicUnsafeGrow :: MVector s (Affine1 a) -> Int -> ST s (MVector s (Affine1 a)) #

Num a => Monoid (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

mempty :: Affine1 a #

mappend :: Affine1 a -> Affine1 a -> Affine1 a #

mconcat :: [Affine1 a] -> Affine1 a #

Num a => Semigroup (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

(<>) :: Affine1 a -> Affine1 a -> Affine1 a #

sconcat :: NonEmpty (Affine1 a) -> Affine1 a #

stimes :: Integral b => b -> Affine1 a -> Affine1 a #

Show a => Show (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

showsPrec :: Int -> Affine1 a -> ShowS #

show :: Affine1 a -> String #

showList :: [Affine1 a] -> ShowS #

Eq a => Eq (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

(==) :: Affine1 a -> Affine1 a -> Bool #

(/=) :: Affine1 a -> Affine1 a -> Bool #

Ord a => Ord (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

compare :: Affine1 a -> Affine1 a -> Ordering #

(<) :: Affine1 a -> Affine1 a -> Bool #

(<=) :: Affine1 a -> Affine1 a -> Bool #

(>) :: Affine1 a -> Affine1 a -> Bool #

(>=) :: Affine1 a -> Affine1 a -> Bool #

max :: Affine1 a -> Affine1 a -> Affine1 a #

min :: Affine1 a -> Affine1 a -> Affine1 a #

Unbox a => Unbox (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Num a => SegAct (Affine1 (Sum a)) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Affine1 (Sum a) -> Sum a -> Sum a #

segActWithLength :: Int -> Affine1 (Sum a) -> Sum a -> Sum a #

Num a => SegAct (Affine1 a) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Affine1 a -> Sum a -> Sum a #

segActWithLength :: Int -> Affine1 a -> Sum a -> Sum a #

Num a => SegAct (Dual (Affine1 (Sum a))) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Dual (Affine1 (Sum a)) -> Sum a -> Sum a #

segActWithLength :: Int -> Dual (Affine1 (Sum a)) -> Sum a -> Sum a #

Num a => SegAct (Dual (Affine1 a)) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

Methods

segAct :: Dual (Affine1 a) -> Sum a -> Sum a #

segActWithLength :: Int -> Dual (Affine1 a) -> Sum a -> Sum a #

newtype MVector s (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

newtype MVector s (Affine1 a) = MV_Affine1 (MVector s (Affine1Repr a))
newtype Vector (Affine1 a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.Affine1

type Affine1Repr a = (a, a) #

Affine1 internal representation. Tuples are not the fastest representation, but it's easier to implement Unbox.

Since: 1.0.0

Range add

newtype RangeAdd a #

Range set monoid action.

Example

>>> import AtCoder.Extra.Monoid (SegAct(..), RangeAdd(..))
>>> import AtCoder.LazySegTree qualified as LST
>>> import Data.Semigroup (Max(..))
>>> seg <- LST.build @_ @(RangeAdd Int) @(Sum Int) $ VU.generate 3 Sum -- [0, 1, 2]
>>> LST.applyIn seg 0 3 $ RangeAdd 5 -- [5, 6, 7]
>>> getSum <$> LST.prod seg 0 3
18

Since: 1.0.0

Constructors

RangeAdd a 

Instances

Instances details
Unbox a => Vector Vector (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Unbox a => MVector MVector (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Num a => Monoid (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

mempty :: RangeAdd a #

mappend :: RangeAdd a -> RangeAdd a -> RangeAdd a #

mconcat :: [RangeAdd a] -> RangeAdd a #

Num a => Semigroup (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

(<>) :: RangeAdd a -> RangeAdd a -> RangeAdd a #

sconcat :: NonEmpty (RangeAdd a) -> RangeAdd a #

stimes :: Integral b => b -> RangeAdd a -> RangeAdd a #

Show a => Show (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

showsPrec :: Int -> RangeAdd a -> ShowS #

show :: RangeAdd a -> String #

showList :: [RangeAdd a] -> ShowS #

Eq a => Eq (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

(==) :: RangeAdd a -> RangeAdd a -> Bool #

(/=) :: RangeAdd a -> RangeAdd a -> Bool #

Ord a => Ord (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

compare :: RangeAdd a -> RangeAdd a -> Ordering #

(<) :: RangeAdd a -> RangeAdd a -> Bool #

(<=) :: RangeAdd a -> RangeAdd a -> Bool #

(>) :: RangeAdd a -> RangeAdd a -> Bool #

(>=) :: RangeAdd a -> RangeAdd a -> Bool #

max :: RangeAdd a -> RangeAdd a -> RangeAdd a #

min :: RangeAdd a -> RangeAdd a -> RangeAdd a #

Unbox a => Unbox (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Num a => SegAct (RangeAdd a) (Sum a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

Methods

segAct :: RangeAdd a -> Sum a -> Sum a #

segActWithLength :: Int -> RangeAdd a -> Sum a -> Sum a #

newtype MVector s (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

newtype MVector s (RangeAdd a) = MV_RangeAdd (MVector s a)
newtype Vector (RangeAdd a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAdd

newtype Vector (RangeAdd a) = V_RangeAdd (Vector a)

newtype RangeAddId a #

Range set monoid action.

Example

>>> import AtCoder.Extra.Monoid (SegAct(..), RangeAddId(..))
>>> import AtCoder.LazySegTree qualified as LST
>>> import Data.Semigroup (Max(..))
>>> seg <- LST.build @_ @(RangeAddId Int) @(Max Int) $ VU.generate 3 Max -- [0, 1, 2]
>>> LST.applyIn seg 0 3 $ RangeAddId 5 -- [5, 6, 7]
>>> getMax <$> LST.prod seg 0 3
7

Since: 1.0.0

Constructors

RangeAddId a 

Instances

Instances details
Unbox a => Vector Vector (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Unbox a => MVector MVector (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Num a => Monoid (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Num a => Semigroup (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Show a => Show (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Eq a => Eq (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Methods

(==) :: RangeAddId a -> RangeAddId a -> Bool #

(/=) :: RangeAddId a -> RangeAddId a -> Bool #

Ord a => Ord (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Unbox a => Unbox (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Num a => SegAct (RangeAddId a) (Max a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Methods

segAct :: RangeAddId a -> Max a -> Max a #

segActWithLength :: Int -> RangeAddId a -> Max a -> Max a #

Num a => SegAct (RangeAddId a) (Min a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Methods

segAct :: RangeAddId a -> Min a -> Min a #

segActWithLength :: Int -> RangeAddId a -> Min a -> Min a #

newtype MVector s (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

newtype MVector s (RangeAddId a) = MV_RangeAddId (MVector s a)
newtype Vector (RangeAddId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeAddId

Range set

newtype RangeSet a #

SegAct instance of range set action.

Example

>>> import AtCoder.Extra.Monoid (SegAct(..), RangeSet(..))
>>> import AtCoder.LazySegTree qualified as LST
>>> import Data.Semigroup (Product(..))
>>> seg <- LST.build @_ @(RangeSet (Product Int)) @(Product Int) $ VU.generate 4 Product -- [0, 1, 2, 3]
>>> LST.applyIn seg 0 3 $ RangeSet (True, Product 5) -- [5, 5, 5, 3]
>>> getProduct <$> LST.prod seg 0 4
375

Since: 1.0.0

Constructors

RangeSet (RangeSetRepr a) 

Instances

Instances details
Unbox a => Vector Vector (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Unbox a => MVector MVector (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Monoid a => Monoid (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

mempty :: RangeSet a #

mappend :: RangeSet a -> RangeSet a -> RangeSet a #

mconcat :: [RangeSet a] -> RangeSet a #

Semigroup (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

(<>) :: RangeSet a -> RangeSet a -> RangeSet a #

sconcat :: NonEmpty (RangeSet a) -> RangeSet a #

stimes :: Integral b => b -> RangeSet a -> RangeSet a #

Show a => Show (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

showsPrec :: Int -> RangeSet a -> ShowS #

show :: RangeSet a -> String #

showList :: [RangeSet a] -> ShowS #

Eq a => Eq (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

(==) :: RangeSet a -> RangeSet a -> Bool #

(/=) :: RangeSet a -> RangeSet a -> Bool #

Ord a => Ord (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

compare :: RangeSet a -> RangeSet a -> Ordering #

(<) :: RangeSet a -> RangeSet a -> Bool #

(<=) :: RangeSet a -> RangeSet a -> Bool #

(>) :: RangeSet a -> RangeSet a -> Bool #

(>=) :: RangeSet a -> RangeSet a -> Bool #

max :: RangeSet a -> RangeSet a -> RangeSet a #

min :: RangeSet a -> RangeSet a -> RangeSet a #

Unbox a => Unbox (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Monoid a => SegAct (RangeSet a) a #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

Methods

segAct :: RangeSet a -> a -> a #

segActWithLength :: Int -> RangeSet a -> a -> a #

newtype MVector s (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

newtype MVector s (RangeSet a) = MV_RangeSet (MVector s (RangeSetRepr a))
newtype Vector (RangeSet a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSet

newtype Vector (RangeSet a) = V_RangeSet (Vector (RangeSetRepr a))

newtype RangeSetId a #

SegAct instance of range set action over ideomponent monoids.

Example

>>> import AtCoder.Extra.Monoid (SegAct(..), RangeSetId(..))
>>> import AtCoder.LazySegTree qualified as LST
>>> import Data.Semigroup (Max(..))
>>> seg <- LST.build @_ @(RangeSetId (Max Int)) @(Max Int) $ VU.generate 3 (Max . (+ 10)) -- [10, 11, 12]
>>> LST.applyIn seg 0 2 $ RangeSetId (True, Max 5) -- [5, 5, 12]
>>> getMax <$> LST.prod seg 0 3
12

Since: 1.0.0

Constructors

RangeSetId (RangeSetIdRepr a) 

Instances

Instances details
Unbox a => Vector Vector (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Unbox a => MVector MVector (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Monoid a => Monoid (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Semigroup (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Show a => Show (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Eq a => Eq (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Methods

(==) :: RangeSetId a -> RangeSetId a -> Bool #

(/=) :: RangeSetId a -> RangeSetId a -> Bool #

Ord a => Ord (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Unbox a => Unbox (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

(Ord a, Bounded a) => SegAct (RangeSetId (Max a)) (Max a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Methods

segAct :: RangeSetId (Max a) -> Max a -> Max a #

segActWithLength :: Int -> RangeSetId (Max a) -> Max a -> Max a #

(Ord a, Bounded a) => SegAct (RangeSetId (Min a)) (Min a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

Methods

segAct :: RangeSetId (Min a) -> Min a -> Min a #

segActWithLength :: Int -> RangeSetId (Min a) -> Min a -> Min a #

newtype MVector s (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

newtype MVector s (RangeSetId a) = MV_RangeSetId (MVector s (RangeSetIdRepr a))
newtype Vector (RangeSetId a) #

Since: 1.0.0

Instance details

Defined in AtCoder.Extra.Monoid.RangeSetId

newtype Vector (RangeSetId a) = V_RangeSetId (Vector (RangeSetIdRepr a))