Struct SegmentTree

Source
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(N)$
Source

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

配列から初期化する

  • 時間計算量: $O(N)$
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: Monoid> SegmentTree<M>

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> 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>

Source§

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(&self) -> Option<usize>

<required> 根を取得する
Source§

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

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

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

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

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

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

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

再帰的にprintを行う
Source§

fn print_as_binary_tree(&self)

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

Auto Trait Implementations§

§

impl<M> Freeze for SegmentTree<M>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V