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 C++ (GCC 9.2.1 with AC Library v1.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>

#include <atcoder/all>
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; --i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repc2(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;

using mint = modint998244353;
mint ten = mint(10);
struct S {
    mint a;
    int size;
    int p;
};

struct F {
    mint b;
    bool flag;
};

S op(S l, S r) {
    l.a *= ten.pow(l.p);
    r.a *= ten.pow(r.p);
    return S{l.a + r.a, l.size + r.size, 0};
}

S e() {
    return S{mint(0), 0, 0};
}

S mapping(F l, S r) {
    if (l.flag)
        return S{l.b, 1, r.p};
    return r;
}

F composition(F l, F r) {
    if (!l.flag && r.flag)
        return r;
    return l;
}

F id() {
    return F{0, false};
}

int n, q;

int main() {
    cin >> n >> q;
    vector<S> v(n);
    rep(i, n) { v[i] = S{mint(1), 1, (int)(n - i - 1)}; }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    cerr << seg.all_prod().a.val() << endl;
    rep(i, q) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        l--;
        seg.apply(l, r, F{mint(d), true});
        cout << (seg.all_prod().a * ten.pow(seg.all_prod().p)).val() << endl;
    }
    return 0;
}