Struct seg_tree::segment_tree::LazySegmentTree
source · [−]pub struct LazySegmentTree<T: LazyNode> { /* private fields */ }
Expand description
Lazy segment tree with range queries and range updates.
It uses O(n)
space, assuming that each node uses O(1)
space.
Implementations
sourceimpl<T: LazyNode + Clone> LazySegmentTree<T>
impl<T: LazyNode + Clone> LazySegmentTree<T>
sourcepub fn build(values: &[T]) -> Self
pub fn build(values: &[T]) -> Self
Builds lazy segment tree from slice, each element of the slice will correspond to a leaf of the segment tree.
It has time complexity of O(n*log(n))
, assuming that combine has constant time complexity.
sourcepub fn update(&mut self, i: usize, j: usize, value: <T as Node>::Value)
pub fn update(&mut self, i: usize, j: usize, value: <T as Node>::Value)
Updates the range [i,j] with value.
It will panic if i or j is not in [0,n).
It has time complexity of O(log(n))
, assuming that combine, update_lazy_value and update_lazy_value have constant time complexity.
sourcepub fn query(&mut self, left: usize, right: usize) -> Option<T>
pub fn query(&mut self, left: usize, right: usize) -> Option<T>
Returns the result from the range [left,right].
It returns None if and only if range is empty.
It will panic if left or right are not in [0,n).
It has time complexity of O(log(n))
, assuming that combine, update_lazy_value and update_lazy_value have constant time complexity.
Auto Trait Implementations
impl<T> RefUnwindSafe for LazySegmentTree<T> where
T: RefUnwindSafe,
impl<T> Send for LazySegmentTree<T> where
T: Send,
impl<T> Sync for LazySegmentTree<T> where
T: Sync,
impl<T> Unpin for LazySegmentTree<T> where
T: Unpin,
impl<T> UnwindSafe for LazySegmentTree<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more