library_checker/datastructure/
queue_operate_all_composite.rs1use competitive::prelude::*;
2#[doc(no_inline)]
3pub use competitive::{
4 algebra::LinearOperation,
5 data_structure::QueueAggregation,
6 num::{MInt, mint_basic::MInt998244353},
7};
8
9#[verify::library_checker("queue_operate_all_composite")]
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}