Struct QueueAggregation

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

Implementations§

Source§

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

Source

pub fn new() -> Self

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_3_d.rs (line 10)
6pub fn dsl_3_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, l, a: [u64]);
10    let mut que = QueueAggregation::<MinOperation<_>>::new();
11    let mut ans = Vec::with_capacity(n - l + 1);
12    for a in a.take(n) {
13        que.push(a);
14        if que.len() == l {
15            ans.push(que.fold_all());
16            que.pop();
17        }
18    }
19    iter_print!(writer, @it ans);
20}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_3_a.rs (line 10)
6pub fn dsl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, s: u64, a: [u64]);
10    let mut que = QueueAggregation::<AdditiveOperation<_>>::new();
11    let mut ans = usize::MAX;
12    for a in a.take(n) {
13        que.push(a);
14        while que.fold_all() >= s {
15            ans = ans.min(que.len());
16            que.pop();
17        }
18    }
19    writeln!(writer, "{}", if ans == usize::MAX { 0 } else { ans }).ok();
20}
crates/library_checker/src/datastructure/queue_operate_all_composite.rs (line 14)
10pub fn queue_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 que = QueueAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                que.push(ab);
20            }
21            1 => {
22                que.pop();
23            }
24            2 => {
25                scan!(scanner, x: MInt998244353);
26                let (a, b) = que.fold_all();
27                writeln!(writer, "{}", a * x + b).ok();
28            }
29            _ => panic!("unknown query"),
30        }
31    }
32}
Source

pub fn len(&self) -> usize

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_3_d.rs (line 14)
6pub fn dsl_3_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, l, a: [u64]);
10    let mut que = QueueAggregation::<MinOperation<_>>::new();
11    let mut ans = Vec::with_capacity(n - l + 1);
12    for a in a.take(n) {
13        que.push(a);
14        if que.len() == l {
15            ans.push(que.fold_all());
16            que.pop();
17        }
18    }
19    iter_print!(writer, @it ans);
20}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_3_a.rs (line 15)
6pub fn dsl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, s: u64, a: [u64]);
10    let mut que = QueueAggregation::<AdditiveOperation<_>>::new();
11    let mut ans = usize::MAX;
12    for a in a.take(n) {
13        que.push(a);
14        while que.fold_all() >= s {
15            ans = ans.min(que.len());
16            que.pop();
17        }
18    }
19    writeln!(writer, "{}", if ans == usize::MAX { 0 } else { ans }).ok();
20}
Source

pub fn is_empty(&self) -> bool

Source

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

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_3_d.rs (line 15)
6pub fn dsl_3_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, l, a: [u64]);
10    let mut que = QueueAggregation::<MinOperation<_>>::new();
11    let mut ans = Vec::with_capacity(n - l + 1);
12    for a in a.take(n) {
13        que.push(a);
14        if que.len() == l {
15            ans.push(que.fold_all());
16            que.pop();
17        }
18    }
19    iter_print!(writer, @it ans);
20}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_3_a.rs (line 14)
6pub fn dsl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, s: u64, a: [u64]);
10    let mut que = QueueAggregation::<AdditiveOperation<_>>::new();
11    let mut ans = usize::MAX;
12    for a in a.take(n) {
13        que.push(a);
14        while que.fold_all() >= s {
15            ans = ans.min(que.len());
16            que.pop();
17        }
18    }
19    writeln!(writer, "{}", if ans == usize::MAX { 0 } else { ans }).ok();
20}
crates/library_checker/src/datastructure/queue_operate_all_composite.rs (line 26)
10pub fn queue_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 que = QueueAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                que.push(ab);
20            }
21            1 => {
22                que.pop();
23            }
24            2 => {
25                scan!(scanner, x: MInt998244353);
26                let (a, b) = que.fold_all();
27                writeln!(writer, "{}", a * x + b).ok();
28            }
29            _ => panic!("unknown query"),
30        }
31    }
32}
Source

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

Source

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

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_3_d.rs (line 13)
6pub fn dsl_3_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, l, a: [u64]);
10    let mut que = QueueAggregation::<MinOperation<_>>::new();
11    let mut ans = Vec::with_capacity(n - l + 1);
12    for a in a.take(n) {
13        que.push(a);
14        if que.len() == l {
15            ans.push(que.fold_all());
16            que.pop();
17        }
18    }
19    iter_print!(writer, @it ans);
20}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_3_a.rs (line 13)
6pub fn dsl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, s: u64, a: [u64]);
10    let mut que = QueueAggregation::<AdditiveOperation<_>>::new();
11    let mut ans = usize::MAX;
12    for a in a.take(n) {
13        que.push(a);
14        while que.fold_all() >= s {
15            ans = ans.min(que.len());
16            que.pop();
17        }
18    }
19    writeln!(writer, "{}", if ans == usize::MAX { 0 } else { ans }).ok();
20}
crates/library_checker/src/datastructure/queue_operate_all_composite.rs (line 19)
10pub fn queue_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 que = QueueAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                que.push(ab);
20            }
21            1 => {
22                que.pop();
23            }
24            2 => {
25                scan!(scanner, x: MInt998244353);
26                let (a, b) = que.fold_all();
27                writeln!(writer, "{}", a * x + b).ok();
28            }
29            _ => panic!("unknown query"),
30        }
31    }
32}
Source

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

Examples found in repository?
crates/aizu_online_judge/src/dsl/dsl_3_d.rs (line 16)
6pub fn dsl_3_d(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, l, a: [u64]);
10    let mut que = QueueAggregation::<MinOperation<_>>::new();
11    let mut ans = Vec::with_capacity(n - l + 1);
12    for a in a.take(n) {
13        que.push(a);
14        if que.len() == l {
15            ans.push(que.fold_all());
16            que.pop();
17        }
18    }
19    iter_print!(writer, @it ans);
20}
More examples
Hide additional examples
crates/aizu_online_judge/src/dsl/dsl_3_a.rs (line 16)
6pub fn dsl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, s: u64, a: [u64]);
10    let mut que = QueueAggregation::<AdditiveOperation<_>>::new();
11    let mut ans = usize::MAX;
12    for a in a.take(n) {
13        que.push(a);
14        while que.fold_all() >= s {
15            ans = ans.min(que.len());
16            que.pop();
17        }
18    }
19    writeln!(writer, "{}", if ans == usize::MAX { 0 } else { ans }).ok();
20}
crates/library_checker/src/datastructure/queue_operate_all_composite.rs (line 22)
10pub fn queue_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 que = QueueAggregation::<LinearOperation<_>>::new();
15    for _ in 0..q {
16        match scanner.scan::<usize>() {
17            0 => {
18                scan!(scanner, ab: (MInt998244353, MInt998244353));
19                que.push(ab);
20            }
21            1 => {
22                que.pop();
23            }
24            2 => {
25                scan!(scanner, x: MInt998244353);
26                let (a, b) = que.fold_all();
27                writeln!(writer, "{}", a * x + b).ok();
28            }
29            _ => panic!("unknown query"),
30        }
31    }
32}

Trait Implementations§

Source§

impl<M> Clone for QueueAggregation<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 QueueAggregation<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 QueueAggregation<M>
where M: Monoid,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<M> Freeze for QueueAggregation<M>

§

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

§

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

§

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

§

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

§

impl<M> UnwindSafe for QueueAggregation<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.