pub struct SegmentTree<T, F> { /* private fields */ }
Expand description

注意⚠ この実装は遅いので time limit の厳しい問題には代わりに ACL のセグメントツリーを使うこと。

セグメントツリーです。

Implementations§

source§

impl<T, F> SegmentTree<T, F>where T: Clone, F: Fn(&T, &T) -> T,

source

pub fn new(n: usize, e: T, multiply: F) -> Self

長さ n の列を初期値 e で初期化します。

multiply は fold に使う二項演算です。

source

pub fn get(&self, i: usize) -> &T

列の i 番目の要素を取得します。

source

pub fn set(&mut self, i: usize, x: T)

列の i 番目の要素を x で更新します。

source

pub fn update<U>(&mut self, i: usize, f: U)where U: FnOnce(&T) -> T,

列の i 番目の要素を f で更新します。

source

pub fn fold(&self, range: impl RangeBounds<usize>) -> T

rangel..r として、multiply(l番目の要素, multiply(..., multiply(r-2番目の要素, r-1番目の要素))) の値を返します。

Trait Implementations§

source§

impl<T: Clone, F: Clone> Clone for SegmentTree<T, F>

source§

fn clone(&self) -> SegmentTree<T, F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, F> Debug for SegmentTree<T, F>where T: Debug,

source§

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

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

impl<T, F> Index<usize> for SegmentTree<T, F>where T: Clone, F: Fn(&T, &T) -> T,

§

type Output = T

The returned type after indexing.
source§

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

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

Auto Trait Implementations§

§

impl<T, F> RefUnwindSafe for SegmentTree<T, F>where F: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, F> Send for SegmentTree<T, F>where F: Send, T: Send,

§

impl<T, F> Sync for SegmentTree<T, F>where F: Sync, T: Sync,

§

impl<T, F> Unpin for SegmentTree<T, F>where F: Unpin, T: Unpin,

§

impl<T, F> UnwindSafe for SegmentTree<T, F>where F: UnwindSafe, T: 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.