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: Wrong Answer)

#[allow(unused)]
use {
    std::error::Error,
    std::fmt::Debug,
    std::str::FromStr,
    std::io::prelude::*,
    std::io::{stdin, stdout, BufReader, BufWriter},
    std::collections::{HashSet, BinaryHeap},
    std::cmp::min,
    std::mem::swap,
    std::char::from_digit,
};

type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;

const MOD: u64 = 998244353;
const M: usize = 200000;

fn main() -> BoxResult<()> {
    let mut scanner = Scanner::new(stdin());
    let mut values = vec![vec![0; M + 1]; 10];
    for i in 1..10 {
        let mut sum = 0;
        let mut crt = i as u64;
        for j in 1..(M + 1) {
            if j > 1 {
                crt = (crt * 10) % MOD;
            }
            sum = (sum + crt) % MOD;
            values[i][j] = sum;
        }
    }
    let (n, q) = scanner.read_two::<usize, usize>()?;
    let mut tree = SegmentTree::new(n + 1, values);
    let mut writer = BufWriter::new(stdout());
    for _ in 0..q {
        let (l, r, d) = scanner.read_three::<usize, usize, usize>()?;
        tree.set(l, r, d);
        writeln!(&mut writer, "{}", tree.query())?;
    }
    Ok(())
}

struct SegmentTree {
    size: usize,
    len: usize,
    values: Vec<u64>,
    cumsum: Vec<Vec<u64>>,
}

impl SegmentTree {
    fn new(size: usize, cumsum: Vec<Vec<u64>>) -> Self {
        let mut len = 1;
        while len < size {
            len *= 2;
        }
        let values = vec![0; 2 * len - 1];
        Self {
            size,
            len,
            values,
            cumsum
        }
    }

    fn set(&mut self, s: usize, e: usize, x: usize) {
        self.set_rec(s, e, x, 0, 0, self.len - 1);
    }

    fn set_rec(&mut self, s: usize, e: usize, x: usize, index: usize, l: usize, r: usize) -> u64 {
        if s == l && e == r {
            let old = self.values[index];
            self.values[index] = (self.cumsum[x][e] + MOD - self.cumsum[x][s - 1]) % MOD;
            return (self.values[index] + MOD - old) % MOD;
        }
        let mid = (l + r) / 2;
        let mut old = 0;
        if e <= mid {
            old = self.set_rec(s, e, x, 2 * index + 1, l, mid);
        } else if s > mid {
            old = self.set_rec(s, e, x, 2 * index + 2, mid + 1, r);
        } else {
            old += self.set_rec(s, mid, x, 2 * index + 1, l, mid);
            old += self.set_rec(mid + 1, e, x, 2 * index + 2, mid + 1, r);
        }
        let o = self.values[index];
        self.values[index] += old;
        self.values[index] %= MOD;
        return (self.values[index] + MOD - o) % MOD;
    }

    fn query(&self) -> u64 {
        return self.values[0];
    }
}

pub struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    pub fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    pub fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    pub fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
 
    pub fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    pub fn read_two<T, U>(&mut self) -> BoxResult<(T, U)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            (a, b)
        };
        self.buffer.clear();
        Ok((a, b))
    }
    pub fn read_three<T, U, V>(&mut self) -> BoxResult<(T, U, V)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
        V: FromStr + Copy,
        V::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b, c) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            let c = params[2].parse()?;
            (a, b, c)
        };
        self.buffer.clear();
        Ok((a, b, c))
    }
    pub fn read_four<T, U, V, W>(&mut self) -> BoxResult<(T, U, V, W)>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
        U: FromStr + Copy,
        U::Err: Debug + Error + 'static,
        V: FromStr + Copy,
        V::Err: Debug + Error + 'static,
        W: FromStr + Copy,
        W::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let (a, b, c, d) = {
            let params = self.buffer.trim().split_whitespace().collect::<Vec<_>>();
            let a = params[0].parse()?;
            let b = params[1].parse()?;
            let c = params[2].parse()?;
            let d = params[3].parse()?;
            (a, b, c, d)
        };
        self.buffer.clear();
        Ok((a, b, c, d))
    }
    pub fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    pub fn read_matrix<T>(&mut self, lines: u64) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr + Copy,
        T::Err: Debug + Error + 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    pub fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}