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,
impl<T> RangeMinimumQuery<T>where
T: Ord,
Sourcepub fn new(data: Vec<T>) -> Self
pub fn new(data: Vec<T>) -> Self
Examples found in repository?
More 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 }pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, index: usize) -> &T
Sourcefn min_index(&self, a: usize, b: usize) -> usize
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 }Sourcefn argmin_in_block(&self, l: usize, r: usize) -> usize
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 }Sourcefn argmin_blocks(&self, l_block: usize, r_block: usize) -> usize
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 }Trait Implementations§
Source§impl<T: Clone> Clone for RangeMinimumQuery<T>
impl<T: Clone> Clone for RangeMinimumQuery<T>
Source§fn clone(&self) -> RangeMinimumQuery<T>
fn clone(&self) -> RangeMinimumQuery<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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> 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