Skip to main content

RangeMinimumQuery

Struct RangeMinimumQuery 

Source
pub struct RangeMinimumQuery<T> {
    data: Vec<T>,
    mask: Vec<u64>,
    sparse: Vec<usize>,
    sparse_offset: Vec<usize>,
}

Fields§

§data: Vec<T>§mask: Vec<u64>§sparse: Vec<usize>§sparse_offset: Vec<usize>

Implementations§

Source§

impl<T> RangeMinimumQuery<T>
where T: Ord,

Source

pub fn new(data: Vec<T>) -> Self

Examples found in repository?
crates/library_checker/src/data_structure/staticrmq.rs (line 35)
31pub fn staticrmq_range_minimum_query(reader: impl Read, mut writer: impl Write) {
32    let s = read_all_unchecked(reader);
33    let mut scanner = Scanner::new(&s);
34    scan!(scanner, n, q, a: [u64; n], lr: [(usize, usize)]);
35    let rmq = RangeMinimumQuery::new(a);
36    for (l, r) in lr.take(q) {
37        writeln!(writer, "{}", rmq.fold(l, r)).ok();
38    }
39}
More examples
Hide additional examples
crates/competitive/src/string/string_search.rs (line 74)
70    pub fn new(text: Vec<T>) -> Self {
71        let suffix_array = SuffixArray::new(&text);
72
73        let (lcp_array, rank) = suffix_array.lcp_array_with_rank(&text);
74        let rmq = RangeMinimumQuery::new(lcp_array.clone());
75
76        Self {
77            text,
78            suffix_array,
79            lcp_array,
80            rank,
81            rmq,
82        }
83    }
crates/competitive/src/tree/euler_tour.rs (line 199)
191    pub fn lca(&self, root: usize) -> LowestCommonAncestor {
192        let depth = self.tree_depth(root);
193        let mut trace = Vec::with_capacity(2 * self.vertices_size() - 1);
194        let mut depth_trace = Vec::with_capacity(2 * self.vertices_size() - 1);
195        let euler_tour = self.full_euler_tour_builder(root).build_with_trace(|u| {
196            trace.push(u);
197            depth_trace.push(depth[u]);
198        });
199        let rmq = RangeMinimumQuery::new(depth_trace);
200        LowestCommonAncestor {
201            euler_tour,
202            trace,
203            rmq,
204        }
205    }
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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

Source

fn min_index(&self, a: usize, b: usize) -> usize

Examples found in repository?
crates/competitive/src/data_structure/range_minimum_query.rs (line 113)
106    fn argmin_blocks(&self, l_block: usize, r_block: usize) -> usize {
107        debug_assert!(l_block < r_block);
108        let len = r_block - l_block;
109        let k = len.ilog2() as usize;
110        let offset = self.sparse_offset[k];
111        let left = self.sparse[offset + l_block];
112        let right = self.sparse[offset + r_block - (1usize << k)];
113        self.min_index(left, right)
114    }
115
116    pub fn argmin(&self, l: usize, r: usize) -> usize {
117        assert!(l < r);
118        assert!(r <= self.data.len());
119        let r = r - 1;
120        let bl = l >> BLOCK_SHIFT;
121        let br = r >> BLOCK_SHIFT;
122        if bl == br {
123            return self.argmin_in_block(l, r);
124        }
125        let left_end = ((bl + 1) << BLOCK_SHIFT) - 1;
126        let right_start = br << BLOCK_SHIFT;
127        let mut best = self.min_index(
128            self.argmin_in_block(l, left_end),
129            self.argmin_in_block(right_start, r),
130        );
131        if bl + 1 < br {
132            let mid = self.argmin_blocks(bl + 1, br);
133            best = self.min_index(best, mid);
134        }
135        best
136    }
Source

fn argmin_in_block(&self, l: usize, r: usize) -> usize

Examples found in repository?
crates/competitive/src/data_structure/range_minimum_query.rs (line 123)
116    pub fn argmin(&self, l: usize, r: usize) -> usize {
117        assert!(l < r);
118        assert!(r <= self.data.len());
119        let r = r - 1;
120        let bl = l >> BLOCK_SHIFT;
121        let br = r >> BLOCK_SHIFT;
122        if bl == br {
123            return self.argmin_in_block(l, r);
124        }
125        let left_end = ((bl + 1) << BLOCK_SHIFT) - 1;
126        let right_start = br << BLOCK_SHIFT;
127        let mut best = self.min_index(
128            self.argmin_in_block(l, left_end),
129            self.argmin_in_block(right_start, r),
130        );
131        if bl + 1 < br {
132            let mid = self.argmin_blocks(bl + 1, br);
133            best = self.min_index(best, mid);
134        }
135        best
136    }
Source

fn argmin_blocks(&self, l_block: usize, r_block: usize) -> usize

Examples found in repository?
crates/competitive/src/data_structure/range_minimum_query.rs (line 132)
116    pub fn argmin(&self, l: usize, r: usize) -> usize {
117        assert!(l < r);
118        assert!(r <= self.data.len());
119        let r = r - 1;
120        let bl = l >> BLOCK_SHIFT;
121        let br = r >> BLOCK_SHIFT;
122        if bl == br {
123            return self.argmin_in_block(l, r);
124        }
125        let left_end = ((bl + 1) << BLOCK_SHIFT) - 1;
126        let right_start = br << BLOCK_SHIFT;
127        let mut best = self.min_index(
128            self.argmin_in_block(l, left_end),
129            self.argmin_in_block(right_start, r),
130        );
131        if bl + 1 < br {
132            let mid = self.argmin_blocks(bl + 1, br);
133            best = self.min_index(best, mid);
134        }
135        best
136    }
Source

pub fn argmin(&self, l: usize, r: usize) -> usize

Examples found in repository?
crates/competitive/src/data_structure/range_minimum_query.rs (line 144)
143    pub fn fold(&self, l: usize, r: usize) -> T {
144        let idx = self.argmin(l, r);
145        self.data[idx].clone()
146    }
More examples
Hide additional examples
crates/competitive/src/tree/euler_tour.rs (line 262)
256    pub fn lca(&self, u: usize, v: usize) -> usize {
257        let mut l = self.euler_tour.vidx[u][0];
258        let mut r = self.euler_tour.vidx[v][0];
259        if l > r {
260            swap(&mut l, &mut r);
261        }
262        let idx = self.rmq.argmin(l, r + 1);
263        self.trace[idx]
264    }
Source§

impl<T> RangeMinimumQuery<T>
where T: Ord + Clone,

Source

pub fn fold(&self, l: usize, r: usize) -> T

Examples found in repository?
crates/competitive/src/string/string_search.rs (line 146)
141    fn lcp_sa(&self, a: usize, b: usize) -> usize {
142        if a == b {
143            return self.text.len() - self.suffix_array[a];
144        }
145        let (l, r) = if a < b { (a, b) } else { (b, a) };
146        self.rmq.fold(l, r)
147    }
More examples
Hide additional examples
crates/library_checker/src/data_structure/staticrmq.rs (line 37)
31pub fn staticrmq_range_minimum_query(reader: impl Read, mut writer: impl Write) {
32    let s = read_all_unchecked(reader);
33    let mut scanner = Scanner::new(&s);
34    scan!(scanner, n, q, a: [u64; n], lr: [(usize, usize)]);
35    let rmq = RangeMinimumQuery::new(a);
36    for (l, r) in lr.take(q) {
37        writeln!(writer, "{}", rmq.fold(l, r)).ok();
38    }
39}

Trait Implementations§

Source§

impl<T: Clone> Clone for RangeMinimumQuery<T>

Source§

fn clone(&self) -> RangeMinimumQuery<T>

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: Debug> Debug for RangeMinimumQuery<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for RangeMinimumQuery<T>

§

impl<T> RefUnwindSafe for RangeMinimumQuery<T>
where T: RefUnwindSafe,

§

impl<T> Send for RangeMinimumQuery<T>
where T: Send,

§

impl<T> Sync for RangeMinimumQuery<T>
where T: Sync,

§

impl<T> Unpin for RangeMinimumQuery<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for RangeMinimumQuery<T>

§

impl<T> UnwindSafe for RangeMinimumQuery<T>
where T: 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> ToArrayVecScalar for T

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.