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