pub struct SegmentTree<M: Monoid> {
    pub N: usize,
    /* private fields */
}
Expand description

セグメント木

Fields§

§N: usize

要素数

Implementations§

source§

impl<T: Ord + Bounded + Clone> SegmentTree<Indexed<Min<T>>>

source

pub fn new_with_index(N: usize) -> Self

セグメント木(インデックス付きで)を初期化する

  • 時間計算量: $O(N)$
source§

impl<T: Ord + Bounded + Clone> SegmentTree<Indexed<Max<T>>>

source

pub fn new_with_index(N: usize) -> Self

セグメント木を(インデックス付きで)初期化する

  • 時間計算量: $O(N)$
source§

impl<M: Monoid> SegmentTree<M>

source

pub fn new(N: usize) -> Self

セグメント木を初期化する

  • 時間計算量: $O(1)$
source

pub fn update(&mut self, index: usize, value: M::Val)

index番目の要素をvalueに更新する

  • 時間計算量: $O(\log N)$
source

pub fn get_mut(&mut self, i: usize) -> Option<ValMut<'_, M>>

i番目の要素の可変な参照を返す

  • 時間計算量: $O(\log N)$
source

pub fn get_range<R: RangeBounds<usize> + Debug>(&self, range: R) -> M::Val

区間rangeの集約を行う

  • 時間計算量: $O(\log N)$
source§

impl<M> SegmentTree<M>where M: OrderedMonoid, M::Val: Debug,

source

pub fn max_right<F>(&self, l: usize, f: F) -> (M::Val, usize)where F: Fn(M::Val) -> bool,

左端を固定した2分探索

  • 引数lと関数fに対して,

    • f( seg.get(l..x) ) = true
    • f( seg.get(l..x+1) ) = false


    を満たすxを返す

引数

  • f :
    • f(e) = true
    • 任意のiに対して,f( seg.get(l..i) ) = falseならば,f( seg.get(l..i+1) ) = false
source

pub fn min_left<F>(&self, r: usize, f: F) -> (M::Val, usize)where F: Fn(M::Val) -> bool,

右端を固定した2分探索

  • 引数rと関数fに対して,

    • f( seg.get(x..r) ) = true
    • f( seg.get(x-1..r) ) = false


    となるようなxを返す

引数

  • f :
    • f(e) = true
    • 任意のiに対して,f( seg.get(i..r) ) = falseならば,f( seg.get(i-1..r) ) = false

Trait Implementations§

source§

impl<M> Debug for SegmentTree<M>where M: Monoid, M::Val: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<M: Monoid> From<Vec<<M as Monoid>::Val, Global>> for SegmentTree<M>

source§

fn from(src: Vec<M::Val>) -> Self

Converts to this type from the input type.
source§

impl<M: Monoid> FromIterator<<M as Monoid>::Val> for SegmentTree<M>

source§

fn from_iter<T: IntoIterator<Item = M::Val>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<M: Monoid> Index<usize> for SegmentTree<M>

§

type Output = <M as Monoid>::Val

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<M> ShowBinaryTree<usize> for SegmentTree<M>where M: Monoid, M::Val: Debug,

source§

fn get_root(&mut self) -> usize

<required> 根を取得する
source§

fn get_left(&mut self, i: &usize) -> Option<usize>

<required> 左の子のポインタを取得する
source§

fn get_right(&mut self, i: &usize) -> Option<usize>

<required> 右の子のポインタを取得する
source§

fn print_node(&mut self, i: &usize) -> String

<required> ノードの値を表示する
source§

fn print_inner( &mut self, ptr: P, fill: &mut Vec<&'static str>, last: &'static str )

再帰的にprintを行う
source§

fn print_as_binary_tree(&mut self)

2分木としてフォーマットする

Auto Trait Implementations§

§

impl<M> RefUnwindSafe for SegmentTree<M>where <M as Monoid>::Val: RefUnwindSafe,

§

impl<M> Send for SegmentTree<M>where <M as Monoid>::Val: Send,

§

impl<M> Sync for SegmentTree<M>where <M as Monoid>::Val: Sync,

§

impl<M> Unpin for SegmentTree<M>where <M as Monoid>::Val: Unpin,

§

impl<M> UnwindSafe for SegmentTree<M>where <M as Monoid>::Val: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V