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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competitive::prelude::*;

type GF = competitive::gf::GF<promote!(998_244_353)>;

#[argio(output = AtCoder)]
fn main(n: usize, q: usize, qs: [(Usize1, usize, i64); q]) {
    let mut ranges = BTreeMap::new();
    ranges.insert((0, n), 1);

    let mut ones = vec![GF::new(0), GF::new(1)];
    let mut tens = vec![GF::new(1)];

    for i in 2..n + 1 {
        ones.push(ones[i - 1] * 10 + 1);
    }

    for i in 1..n + 1 {
        tens.push(tens[i - 1] * 10);
    }

    let mut cur = ones[n];

    let zoro_val = |l, r, d| -> GF {
        let len = r - l;
        ones[len] * tens[l] * d
    };

    for (l, r, d) in qs {
        let (l, r) = (n - r, n - l);

        let mut dels = vec![];
        let mut inss = vec![(l, r, d)];

        for (&(ll, rr), &dd) in ranges.range(..(r, 0)).rev() {
            if rr <= l {
                break;
            }

            dels.push((ll, rr, dd));

            if rr > r {
                inss.push((r, rr, dd));
            }
            if ll < l {
                inss.push((ll, l, dd));
            }
        }

        for (l, r, d) in dels {
            ranges.remove(&(l, r));
            cur -= zoro_val(l, r, d);
        }
        for (l, r, d) in inss {
            ranges.insert((l, r), d);
            cur += zoro_val(l, r, d);
        }

        println!("{}", cur);
    }
}
*/

fn main() {
    let exe = "/tmp/bin9E18D22C";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";