Skip to main content

library_checker/data_structure/
queue_operate_all_composite.rs

1use competitive::prelude::*;
2#[doc(no_inline)]
3pub use competitive::{
4    algebra::LinearOperation,
5    data_structure::QueueAggregation,
6    num::{MInt, mint_basic::MInt998244353},
7};
8
9competitive::define_enum_scan! {
10    enum Query: usize {
11        0 => Push { ab: (MInt998244353, MInt998244353) }
12        1 => Pop
13        2 => Apply { x: MInt998244353 }
14    }
15}
16
17#[verify::library_checker("queue_operate_all_composite")]
18pub fn queue_operate_all_composite(reader: impl Read, mut writer: impl Write) {
19    let s = read_all_unchecked(reader);
20    let mut scanner = Scanner::new(&s);
21    scan!(scanner, q);
22    let mut que = QueueAggregation::<LinearOperation<_>>::new();
23    for _ in 0..q {
24        scan!(scanner, query: Query);
25        match query {
26            Query::Push { ab } => {
27                que.push(ab);
28            }
29            Query::Pop => {
30                que.pop();
31            }
32            Query::Apply { x } => {
33                let (a, b) = que.fold_all();
34                writeln!(writer, "{}", a * x + b).ok();
35            }
36        }
37    }
38}