pub struct SegmentTree { /* private fields */ }Expand description
A segment tree supporting range sum queries and point updates.
Both query and update run in O(log n) time.
Implementations§
Source§impl SegmentTree
impl SegmentTree
Sourcepub fn new(values: &[i64]) -> Self
pub fn new(values: &[i64]) -> Self
Build a segment tree from a slice of values.
Time complexity: O(n).
Sourcepub fn query(&self, l: usize, r: usize) -> i64
pub fn query(&self, l: usize, r: usize) -> i64
Query the sum over the index range [l, r] (inclusive).
Returns 0 for an empty range or out-of-bounds query.
Time complexity: O(log n).
Auto Trait Implementations§
impl Freeze for SegmentTree
impl RefUnwindSafe for SegmentTree
impl Send for SegmentTree
impl Sync for SegmentTree
impl Unpin for SegmentTree
impl UnsafeUnpin for SegmentTree
impl UnwindSafe for SegmentTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more