Problem:
Score : 500 points

Problem Statement

You have a string S of length N.
Initially, all characters in S are 1s.

You will perform queries Q times.
In the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit).
Then, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i.

After each query, read the string S as a decimal integer, and print its value modulo 998,244,353.

Constraints

1 \leq N, Q \leq 200,000

1 \leq L_i \leq R_i \leq N

1 \leq D_i \leq 9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
L_1 R_1 D_1
:
L_Q R_Q D_Q

Output

Print Q lines.
In the i-th line print the value of S after the i-th query, modulo 998,244,353.

Sample Input 1

8 5
3 6 2
1 4 7
3 8 3
2 2 2
4 5 1

Sample Output 1

11222211
77772211
77333333
72333333
72311333

Sample Input 2

200000 1
123 456 7

Sample Output 2

641437905

Don't forget to take the modulo.

Solution in Rust (1.42.0) (judge verdict: Accepted)

#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Mint(i64);
impl Mint {
    fn new(x: i64) -> Self {
        Mint(x.rem_euclid(MOD))
    }
    fn pow(self, n: usize) -> Self {
        match n {
            0 => Mint::new(1),
            _ => {
                let mut a = self.pow(n >> 1);
                a *= a;
                if n & 1 == 1 {
                    a *= self;
                }
                a
            }
        }
    }
    fn inv(self) -> Self {
        self.pow((MOD - 2) as usize)
    }
}
impl std::ops::Neg for Mint {
    type Output = Mint;
    fn neg(self) -> Self::Output {
        Self::new(-self.0)
    }
}
impl std::ops::AddAssign<Mint> for Mint {
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        self.0 %= MOD;
    }
}
impl std::ops::AddAssign<i64> for Mint {
    fn add_assign(&mut self, rhs: i64) {
        *self += Mint::new(rhs);
    }
}
impl<T> std::ops::Add<T> for Mint
where
    Mint: std::ops::AddAssign<T>,
{
    type Output = Self;
    fn add(self, other: T) -> Self {
        let mut res = self;
        res += other;
        res
    }
}
impl std::ops::SubAssign<Mint> for Mint {
    fn sub_assign(&mut self, rhs: Self) {
        self.0 -= rhs.0;
        if self.0 < 0 {
            self.0 += MOD;
        }
    }
}
impl std::ops::SubAssign<i64> for Mint {
    fn sub_assign(&mut self, rhs: i64) {
        *self -= Mint::new(rhs);
    }
}
impl<T> std::ops::Sub<T> for Mint
where
    Mint: std::ops::SubAssign<T>,
{
    type Output = Self;
    fn sub(self, other: T) -> Self {
        let mut res = self;
        res -= other;
        res
    }
}
impl std::ops::MulAssign<Mint> for Mint {
    fn mul_assign(&mut self, rhs: Self) {
        self.0 *= rhs.0;
        self.0 %= MOD;
    }
}
impl std::ops::MulAssign<i64> for Mint {
    fn mul_assign(&mut self, rhs: i64) {
        *self *= Mint::new(rhs);
    }
}
impl<T> std::ops::Mul<T> for Mint
where
    Mint: std::ops::MulAssign<T>,
{
    type Output = Self;
    fn mul(self, other: T) -> Self {
        let mut res = self;
        res *= other;
        res
    }
}
impl std::ops::DivAssign<Mint> for Mint {
    fn div_assign(&mut self, rhs: Self) {
        *self *= rhs.inv();
    }
}
impl std::ops::DivAssign<i64> for Mint {
    fn div_assign(&mut self, rhs: i64) {
        *self /= Mint::new(rhs);
    }
}
impl<T> std::ops::Div<T> for Mint
where
    Mint: std::ops::DivAssign<T>,
{
    type Output = Self;
    fn div(self, other: T) -> Self {
        let mut res = self;
        res /= other;
        res
    }
}
impl std::fmt::Display for Mint {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl std::ops::Deref for Mint {
    type Target = i64;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl std::ops::DerefMut for Mint {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}

trait ME {
    type M: Clone;
    type E: Clone + PartialEq;
    fn e() -> Self::M;
    fn id() -> (Self::M, Option<Self::E>) {
        (Self::e(), None)
    }
    fn f(a: &Self::M, b: &Self::M) -> Self::M;
    fn g(a: &Self::M, b: &Self::E) -> Self::M;
    fn h(a: &Self::E, b: &Self::E) -> Self::E;
    fn p(a: &Self::E, k: usize) -> Self::E;
}
struct LazySegmentTree<T: ME> {
    n: usize,
    width: usize,
    dat: Vec<(T::M, Option<T::E>)>,
}
#[allow(dead_code)]
impl<T: ME> LazySegmentTree<T> {
    fn new(n: usize) -> Self {
        let width = n.next_power_of_two();
        Self {
            n,
            width,
            dat: vec![T::id(); (width << 1) - 1],
        }
    }
    fn from_vec(a: &[T::M]) -> Self {
        let n = a.len();
        let width = n.next_power_of_two();
        let mut dat = vec![T::id(); (width << 1) - 1];
        for i in 0..n {
            dat[i + width - 1].0 = a[i].clone();
        }
        for i in (0..width - 1).rev() {
            dat[i].0 = T::f(&dat[(i << 1) + 1].0, &dat[(i << 1) + 2].0);
        }
        Self { n, width, dat }
    }
    fn __eval(&mut self, now: usize, k: usize) {
        if let Some(x) = &self.dat[now].1 {
            let x = T::p(&x, k);
            self.dat[now].0 = T::g(&self.dat[now].0, &x);
            if k > 1 {
                self.dat[(now << 1) + 1].1 = if let Some(y) = &self.dat[(now << 1) + 1].1 {
                    Some(T::h(y, &x))
                } else {
                    Some(x.clone())
                };
                self.dat[(now << 1) + 2].1 = if let Some(y) = &self.dat[(now << 1) + 2].1 {
                    Some(T::h(y, &x))
                } else {
                    Some(x.clone())
                };
            }
            self.dat[now].1 = None;
        }
    }
    fn __update(&mut self, x: &T::E, now: usize, lc: usize, rc: usize, l: usize, r: usize) {
        self.__eval(now, rc - lc);
        if l <= lc && rc <= r {
            self.dat[now].1 = if let Some(e) = &self.dat[now].1 {
                Some(T::h(&e, &x))
            } else {
                Some(x.clone())
            };
            self.__eval(now, rc - lc);
        } else if l < rc && lc < r {
            self.__update(x, (now << 1) + 1, lc, (lc + rc) / 2, l, r);
            self.__update(x, (now << 1) + 2, (lc + rc) / 2, rc, l, r);
            self.dat[now].0 = T::f(&self.dat[(now << 1) + 1].0, &self.dat[(now << 1) + 2].0);
        }
    }
    fn update<R>(&mut self, range: R, x: &T::E)
    where
        R: std::ops::RangeBounds<usize>,
    {
        let l = match range.start_bound() {
            std::ops::Bound::Included(&a) => a,
            _ => 0,
        };
        let r = match range.end_bound() {
            std::ops::Bound::Excluded(&a) => a,
            std::ops::Bound::Included(&a) => a + 1,
            _ => self.n,
        };
        self.__update(x, 0, 0, self.width, l, r);
    }
    fn __prod(&mut self, now: usize, lc: usize, rc: usize, l: usize, r: usize) -> T::M {
        self.__eval(now, rc - lc);
        if rc <= l || r <= lc {
            T::e()
        } else if l <= lc && rc <= r {
            self.dat[now].0.clone()
        } else {
            T::f(
                &self.__prod((now << 1) + 1, lc, (lc + rc) >> 1, l, r),
                &self.__prod((now << 1) + 2, (lc + rc) >> 1, rc, l, r),
            )
        }
    }
    fn prod<R>(&mut self, range: R) -> T::M
    where
        R: std::ops::RangeBounds<usize>,
    {
        let l = match range.start_bound() {
            std::ops::Bound::Included(&a) => a,
            _ => 0,
        };
        let r = match range.end_bound() {
            std::ops::Bound::Excluded(&a) => a,
            std::ops::Bound::Included(&a) => a + 1,
            _ => self.n,
        };
        self.__prod(0, 0, self.width, l, r)
    }
}

struct Node;
impl ME for Node {
    type M = (Mint, Mint);
    type E = i64;
    fn e() -> Self::M {
        (Mint(0), Mint(1))
    }
    fn f(&(a, k): &Self::M, &(b, l): &Self::M) -> Self::M {
        (a * l + b, k * l)
    }
    fn g(&(_, k): &Self::M, &b: &Self::E) -> Self::M {
        unsafe { ((k - 1) * b * INV9, k) }
    }
    fn h(_a: &Self::E, &b: &Self::E) -> Self::E {
        b
    }
    fn p(&a: &Self::E, _k: usize) -> Self::E {
        a
    }
}
const MOD: i64 = 998244353;
static mut INV9: Mint = Mint(1);

#[fastout]
fn main() {
    input! {
        n: usize,
        q: usize,
        lrd: [(Usize1, Usize1, i64); q],
    }
    unsafe {
        INV9 /= 9;
    }
    let mut seg = {
        let v: Vec<_> = (0..n).map(|_| (Mint(1), Mint(10))).collect();
        LazySegmentTree::<Node>::from_vec(&v)
    };

    for (l, r, d) in lrd {
        seg.update(l..=r, &d);
        let ans = seg.prod(..).0;
        println!("{}", ans);
    }
}