Struct DequeAggregation

Source
pub struct DequeAggregation<M>
where M: Monoid,
{ /* private fields */ }

Implementations§

Source§

impl<M> DequeAggregation<M>
where M: Monoid,

Source

pub fn new() -> Self

Examples found in repository?
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 14)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn fold_all(&self) -> M::T

Examples found in repository?
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 33)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}
Source

pub fn front(&self) -> Option<&M::T>

Source

pub fn back(&self) -> Option<&M::T>

Source

pub fn push_front(&mut self, value: M::T)

Examples found in repository?
crates/competitive/src/data_structure/sliding_winsow_aggregation.rs (line 194)
189    pub fn pop_front(&mut self) -> Option<M::T> {
190        if self.front_stack.is_empty() {
191            let n = self.back_stack.len();
192            let mut back_stack = std::mem::take(&mut self.back_stack);
193            for x in back_stack.drain(..(n + 1) / 2).map(|t| t.1).rev() {
194                self.push_front(x);
195            }
196            for x in back_stack.drain(..).map(|t| t.1) {
197                self.push_back(x);
198            }
199        }
200        self.front_stack.pop().map(|t| t.1)
201    }
202    pub fn pop_back(&mut self) -> Option<M::T> {
203        if self.back_stack.is_empty() {
204            let n = self.front_stack.len();
205            let mut front_stack = std::mem::take(&mut self.front_stack);
206            for x in front_stack.drain(..(n + 1) / 2).map(|t| t.1).rev() {
207                self.push_back(x);
208            }
209            for x in front_stack.drain(..).map(|t| t.1) {
210                self.push_front(x);
211            }
212        }
213        self.back_stack.pop().map(|t| t.1)
214    }
More examples
Hide additional examples
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 19)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}
Source

pub fn push_back(&mut self, value: M::T)

Examples found in repository?
crates/competitive/src/data_structure/sliding_winsow_aggregation.rs (line 197)
189    pub fn pop_front(&mut self) -> Option<M::T> {
190        if self.front_stack.is_empty() {
191            let n = self.back_stack.len();
192            let mut back_stack = std::mem::take(&mut self.back_stack);
193            for x in back_stack.drain(..(n + 1) / 2).map(|t| t.1).rev() {
194                self.push_front(x);
195            }
196            for x in back_stack.drain(..).map(|t| t.1) {
197                self.push_back(x);
198            }
199        }
200        self.front_stack.pop().map(|t| t.1)
201    }
202    pub fn pop_back(&mut self) -> Option<M::T> {
203        if self.back_stack.is_empty() {
204            let n = self.front_stack.len();
205            let mut front_stack = std::mem::take(&mut self.front_stack);
206            for x in front_stack.drain(..(n + 1) / 2).map(|t| t.1).rev() {
207                self.push_back(x);
208            }
209            for x in front_stack.drain(..).map(|t| t.1) {
210                self.push_front(x);
211            }
212        }
213        self.back_stack.pop().map(|t| t.1)
214    }
More examples
Hide additional examples
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 23)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}
Source

pub fn pop_front(&mut self) -> Option<M::T>

Examples found in repository?
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 26)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}
Source

pub fn pop_back(&mut self) -> Option<M::T>

Examples found in repository?
crates/library_checker/src/datastructure/deque_operate_all_composite.rs (line 29)
10pub fn deque_operate_all_composite(reader: impl Read, mut writer: impl Write) {
11    let s = read_all_unchecked(reader);
12    let mut scanner = Scanner::new(&s);
13    scan!(scanner, q);
14    let mut deq = DequeAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                deq.push_front(ab);
20            }
21            1 => {
22                scan!(scanner, ab: (MInt998244353, MInt998244353));
23                deq.push_back(ab);
24            }
25            2 => {
26                deq.pop_front();
27            }
28            3 => {
29                deq.pop_back();
30            }
31            4 => {
32                scan!(scanner, x: MInt998244353);
33                let (a, b) = deq.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36            _ => panic!("unknown query"),
37        }
38    }
39}

Trait Implementations§

Source§

impl<M> Clone for DequeAggregation<M>
where M: Monoid,

Source§

fn clone(&self) -> Self

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<M> Debug for DequeAggregation<M>
where M: Monoid, M::T: Debug,

Source§

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

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

impl<M> Default for DequeAggregation<M>
where M: Monoid,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<M> Freeze for DequeAggregation<M>

§

impl<M> RefUnwindSafe for DequeAggregation<M>
where <M as Magma>::T: RefUnwindSafe,

§

impl<M> Send for DequeAggregation<M>
where <M as Magma>::T: Send,

§

impl<M> Sync for DequeAggregation<M>
where <M as Magma>::T: Sync,

§

impl<M> Unpin for DequeAggregation<M>
where <M as Magma>::T: Unpin,

§

impl<M> UnwindSafe for DequeAggregation<M>
where <M as Magma>::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> 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.