https://atcoder.jp/contests/abc298/tasks/abc298_d
剰余を用意して、1なら10倍して足して、2なら数字×10のべき乗を引けばいいのですが、Rustには負数の剰余を取ると負になるというトラップがありますね。
// Writing a Numeral #![allow(non_snake_case)] //////////////////// constants //////////////////// const D: i64 = 998244353; //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } //////////////////// process //////////////////// fn create_pows(b: i64, n: i32) -> Vec<i64> { let mut pows: Vec<i64> = (0..n).map(|_| 1).collect(); for i in 1..(n as usize) { pows[i] = pows[i-1] * b % D } pows } fn f(Q: i32) { let mut a: Vec<i64> = (0..Q+1).map(|_| 1).collect(); let pows: Vec<i64> = create_pows(10, Q+1); let mut first: usize = 0; let mut last: usize = 1; let mut n: i64 = 1; for _ in 0..Q { let v: Vec<i64> = read_vec(); if v[0] == 1 { a[last] = v[1]; n = (n * 10 + v[1]) % D; last += 1 } else if v[0] == 2 { n = (n - a[first] * pows[last-first-1]) % D; if n < 0 { n += D } first += 1 } else { println!("{}", n); } } } fn main() { let Q: i32 = read(); f(Q) }