SegmentTree

Struct SegmentTree 

Source
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番目の要素))) の値を返します。

Source

pub fn max_right<P>(&self, l: usize, f: P) -> usize
where P: Fn(&T) -> bool,

f(fold(l..r)) = true となる最大の r を返します。

§Panics

if f(e) = false

Source

pub fn min_left<P>(&self, r: usize, f: P) -> usize
where P: Fn(&T) -> bool,

f(fold(l..r)) = true となる最小の l を返します。

§Panics

if f(e) = false

Trait Implementations§

Source§

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

Source§

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

Returns a duplicate 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,

Source§

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> Freeze for SegmentTree<T, F>
where T: Freeze, F: Freeze,

§

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

§

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

§

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

§

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

§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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