Struct RangeSumRangeChminChmaxAdd

Source
pub struct RangeSumRangeChminChmaxAdd<T> {
    pub sum: T,
    /* private fields */
}

Fields§

§sum: T

Implementations§

Source§

impl<T> RangeSumRangeChminChmaxAdd<T>
where T: Copy + Zero + One + Ord + Bounded + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq,

Source

pub fn single(key: T, size: T) -> Self

Examples found in repository?
crates/competitive/src/algebra/monoid_action.rs (line 555)
554        fn single_agg(&key: &Self::Key) -> Self::Agg {
555            Self::single(key, T::one())
556        }
557        fn act_key(&x: &Self::Key, a: &Self::Act) -> Self::Key {
558            if <Self::ActMonoid as Unital>::is_unit(a) {
559                x
560            } else {
561                x.max(a.lb).min(a.ub) + a.bias
562            }
563        }
564        fn act_agg(x: &Self::Agg, a: &Self::Act) -> Option<Self::Agg> {
565            Some(if <Self::ActMonoid as Unital>::is_unit(a) {
566                x.clone()
567            } else if x.size.is_zero() {
568                Self::unit()
569            } else if x.min == x.max || a.lb == a.ub || a.lb >= x.max || a.ub <= x.min {
570                Self::single(x.min.max(a.lb).min(a.ub) + a.bias, x.size)
571            } else if x.min2 == x.max {
572                let mut x = x.clone();
573                let min = x.min.max(a.lb) + a.bias;
574                let max = x.max.min(a.ub) + a.bias;
575                x.min = min;
576                x.max2 = min;
577                x.max = max;
578                x.min2 = max;
579                x.sum = min * x.n_min + max * x.n_max;
580                x
581            } else if a.lb < x.min2 && x.max2 < a.ub {
582                let mut x = x.clone();
583                let min = x.min.max(a.lb);
584                let max = x.max.min(a.ub);
585                x.sum = x.sum + (min - x.min) * x.n_min + (max - x.max) * x.n_max + a.bias * x.size;
586                x.min = min + a.bias;
587                x.max = max + a.bias;
588                x.min2 = x.min2 + a.bias;
589                x.max2 = x.max2 + a.bias;
590                x
591            } else {
592                return None;
593            })
594        }
More examples
Hide additional examples
crates/library_checker/src/datastructure/range_chmin_chmax_add_range_sum.rs (line 16)
10pub fn range_chmin_chmax_add_range_sum(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, n, q, a: [Saturating<i64>; n]);
14    let mut seg = LazySegmentTree::<RangeSumRangeChminChmaxAdd<Saturating<i64>>>::from_vec(
15        a.iter()
16            .map(|&a| RangeSumRangeChminChmaxAdd::single(a, Saturating(1)))
17            .collect(),
18    );
19    for _ in 0..q {
20        match scanner.scan::<usize>() {
21            0 => {
22                scan!(scanner, l, r, b: Saturating<i64>);
23                seg.update(l..r, RangeChminChmaxAdd::chmin(b));
24            }
25            1 => {
26                scan!(scanner, l, r, b: Saturating<i64>);
27                seg.update(l..r, RangeChminChmaxAdd::chmax(b));
28            }
29            2 => {
30                scan!(scanner, l, r, b: Saturating<i64>);
31                seg.update(l..r, RangeChminChmaxAdd::add(b));
32            }
33            3 => {
34                scan!(scanner, l, r);
35                writeln!(writer, "{}", seg.fold(l..r).sum).ok();
36            }
37            _ => panic!("unknown query"),
38        }
39    }
40}

Trait Implementations§

Source§

impl<T: Clone> Clone for RangeSumRangeChminChmaxAdd<T>

Source§

fn clone(&self) -> RangeSumRangeChminChmaxAdd<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 RangeSumRangeChminChmaxAdd<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Magma for RangeSumRangeChminChmaxAdd<T>
where T: Copy + Zero + One + Ord + Bounded + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq,

Source§

type T = RangeSumRangeChminChmaxAdd<T>

type of operands: $T$
Source§

fn operate(x: &Self::T, y: &Self::T) -> Self::T

binary operaion: $\circ$
Source§

fn reverse_operate(x: &Self::T, y: &Self::T) -> Self::T

Source§

fn operate_assign(x: &mut Self::T, y: &Self::T)

Source§

impl<T> MonoidAction for RangeSumRangeChminChmaxAdd<T>
where T: Copy + Zero + One + Ord + Bounded + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq,

Source§

type Key = T

Source§

type Agg = RangeSumRangeChminChmaxAdd<T>

Source§

type Act = RangeChminChmaxAdd<T>

Source§

type AggMonoid = RangeSumRangeChminChmaxAdd<T>

Source§

type ActMonoid = RangeChminChmaxAdd<T>

Source§

fn single_agg(key: &Self::Key) -> Self::Agg

Source§

fn act_key(x: &Self::Key, a: &Self::Act) -> Self::Key

Source§

fn act_agg(x: &Self::Agg, a: &Self::Act) -> Option<Self::Agg>

Source§

fn toggle(_x: &mut Self::Agg)

Source§

fn agg_unit() -> Self::Agg

Source§

fn act_unit() -> Self::Act

Source§

fn agg_operate(x: &Self::Agg, y: &Self::Agg) -> Self::Agg

Source§

fn act_operate(x: &Self::Act, y: &Self::Act) -> Self::Act

Source§

fn agg_operate_assign(x: &mut Self::Agg, y: &Self::Agg)

Source§

fn act_operate_assign(x: &mut Self::Act, y: &Self::Act)

Source§

impl<T: PartialEq> PartialEq for RangeSumRangeChminChmaxAdd<T>

Source§

fn eq(&self, other: &RangeSumRangeChminChmaxAdd<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Unital for RangeSumRangeChminChmaxAdd<T>
where T: Copy + Zero + One + Ord + Bounded + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq,

Source§

fn unit() -> Self::T

identity element: $e$
Source§

fn is_unit(x: &Self::T) -> bool
where <Self as Magma>::T: PartialEq,

Source§

fn set_unit(x: &mut Self::T)

Source§

impl<T> Associative for RangeSumRangeChminChmaxAdd<T>
where T: Copy + Zero + One + Ord + Bounded + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + PartialEq,

Source§

impl<T: Eq> Eq for RangeSumRangeChminChmaxAdd<T>

Source§

impl<T> StructuralPartialEq for RangeSumRangeChminChmaxAdd<T>

Auto Trait Implementations§

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<M> Monoid for M
where M: SemiGroup + Unital,

Source§

fn pow<E>(x: Self::T, exp: E) -> Self::T
where E: ExpBits,

binary exponentiation: $x^n = x\circ\ddots\circ x$
Source§

fn fold<I>(iter: I) -> Self::T
where I: IntoIterator<Item = Self::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.
Source§

impl<S> SemiGroup for S
where S: Magma + Associative,