pub struct SlopeTrick {
left: BinaryHeap<i64>,
right: BinaryHeap<i64>,
addl: i64,
addr: i64,
minval: i64,
}Fields§
§left: BinaryHeap<i64>§right: BinaryHeap<i64>§addl: i64§addr: i64§minval: i64Implementations§
Source§impl SlopeTrick
impl SlopeTrick
Sourcefn push_left(&mut self, x: i64)
fn push_left(&mut self, x: i64)
Examples found in repository?
crates/competitive/src/data_structure/slope_trick.rs (line 58)
54 pub fn add_ramp(&mut self, a: i64) {
55 if let Some(x) = self.peek_left() {
56 self.minval += (x - a).max(0);
57 }
58 self.push_left(a);
59 let x = self.pop_left().unwrap();
60 self.push_right(x);
61 }
62 /// f(x) += max(0, (a-x))
63 pub fn add_pmar(&mut self, a: i64) {
64 if let Some(x) = self.peek_right() {
65 self.minval += (a - x).max(0);
66 }
67 self.push_right(a);
68 let x = self.pop_right().unwrap();
69 self.push_left(x);
70 }Sourcefn push_right(&mut self, x: i64)
fn push_right(&mut self, x: i64)
Examples found in repository?
crates/competitive/src/data_structure/slope_trick.rs (line 60)
54 pub fn add_ramp(&mut self, a: i64) {
55 if let Some(x) = self.peek_left() {
56 self.minval += (x - a).max(0);
57 }
58 self.push_left(a);
59 let x = self.pop_left().unwrap();
60 self.push_right(x);
61 }
62 /// f(x) += max(0, (a-x))
63 pub fn add_pmar(&mut self, a: i64) {
64 if let Some(x) = self.peek_right() {
65 self.minval += (a - x).max(0);
66 }
67 self.push_right(a);
68 let x = self.pop_right().unwrap();
69 self.push_left(x);
70 }Sourcefn peek_left(&self) -> Option<i64>
fn peek_left(&self) -> Option<i64>
Examples found in repository?
crates/competitive/src/data_structure/slope_trick.rs (line 47)
46 pub fn min_range(&self) -> (Option<i64>, Option<i64>) {
47 (self.peek_left(), self.peek_right())
48 }
49 /// f(x) += a
50 pub fn add_const(&mut self, a: i64) {
51 self.minval += a;
52 }
53 /// f(x) += max(0, (x-a))
54 pub fn add_ramp(&mut self, a: i64) {
55 if let Some(x) = self.peek_left() {
56 self.minval += (x - a).max(0);
57 }
58 self.push_left(a);
59 let x = self.pop_left().unwrap();
60 self.push_right(x);
61 }Sourcefn peek_right(&self) -> Option<i64>
fn peek_right(&self) -> Option<i64>
Examples found in repository?
crates/competitive/src/data_structure/slope_trick.rs (line 47)
46 pub fn min_range(&self) -> (Option<i64>, Option<i64>) {
47 (self.peek_left(), self.peek_right())
48 }
49 /// f(x) += a
50 pub fn add_const(&mut self, a: i64) {
51 self.minval += a;
52 }
53 /// f(x) += max(0, (x-a))
54 pub fn add_ramp(&mut self, a: i64) {
55 if let Some(x) = self.peek_left() {
56 self.minval += (x - a).max(0);
57 }
58 self.push_left(a);
59 let x = self.pop_left().unwrap();
60 self.push_right(x);
61 }
62 /// f(x) += max(0, (a-x))
63 pub fn add_pmar(&mut self, a: i64) {
64 if let Some(x) = self.peek_right() {
65 self.minval += (a - x).max(0);
66 }
67 self.push_right(a);
68 let x = self.pop_right().unwrap();
69 self.push_left(x);
70 }Sourcepub fn clear_left(&mut self)
pub fn clear_left(&mut self)
right to left accumulated minimum
f’(x) := min f(y) (y >= x)
Sourcepub fn clear_right(&mut self)
pub fn clear_right(&mut self)
left to right accumulated minimum
f’(x) := min f(y) (y <= x)
Sourcepub fn slide_minimum(&mut self, a: i64, b: i64)
pub fn slide_minimum(&mut self, a: i64, b: i64)
f’(x) := min f(y) (x-a <= y <= x-b)
Trait Implementations§
Source§impl Clone for SlopeTrick
impl Clone for SlopeTrick
Source§fn clone(&self) -> SlopeTrick
fn clone(&self) -> SlopeTrick
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 moreSource§impl Debug for SlopeTrick
impl Debug for SlopeTrick
Source§impl Default for SlopeTrick
impl Default for SlopeTrick
Source§fn default() -> SlopeTrick
fn default() -> SlopeTrick
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SlopeTrick
impl RefUnwindSafe for SlopeTrick
impl Send for SlopeTrick
impl Sync for SlopeTrick
impl Unpin for SlopeTrick
impl UnwindSafe for SlopeTrick
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