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 Python (3.8.2) (judge verdict: Accepted)

import sys
import numpy as np

def solve(inp):
    def bit_length(x):
        ret = 0
        while x:
            x >>= 1
            ret += 1
        return ret
    MOD = 998244353
    e = 0
    id_x = -1

    n = inp[0]
    log = bit_length(n)
    size = 1 << log
    d = [e] * (2 * size)
    lz = [id_x] * size

    def op(a, b):
        a1, a2 = a >> 32, a % (1 << 32)
        b1, b2 = b >> 32, b % (1 << 32)
        c1 = (a1 + b1) % MOD
        c2 = (a2 + b2) % MOD
        return (c1 << 32) + c2

    def mapping(x, a):
        if x == -1:
            return a
        a1, a2 = a >> 32, a % (1 << 32)
        c1 = (x * a2) % MOD
        c2 = a2
        return (c1 << 32) + c2

    def composition(x, y):
        if x == -1:
            return y
        return x

    def update(k):
        d[k] = op(d[2 * k], d[2 * k + 1])

    def all_apply(k, f):
        d[k] = mapping(f, d[k])
        if k < size:
            lz[k] = composition(f, lz[k])

    def push(k):
        all_apply(2 * k, lz[k])
        all_apply(2 * k + 1, lz[k])
        lz[k] = id_x

    def build(arr):
        assert len(arr) == n
        for j in range(n):
            d[size + j] = arr[j]
        for j in range(size - 1, 0, -1):
            update(j)

    def all_prod():
        return d[1]

    def range_apply(l, r, f):
        assert 0 <= l <= r <= n
        if l == r:
            return
        l += size
        r += size
        for i in range(log, 0, -1):
            if ((l >> i) << i) != l:
                push(l >> i)
            if ((r >> i) << i) != r:
                push((r - 1) >> i)
        l2 = l
        r2 = r
        while l < r:
            if l & 1:
                all_apply(l, f)
                l += 1
            if r & 1:
                r -= 1
                all_apply(r, f)
            l >>= 1
            r >>= 1
        l = l2
        r = r2
        for i in range(1, log + 1):
            if ((l >> i) << i) != l:
                update(l >> i)
            if ((r >> i) << i) != r:
                update((r - 1) >> i)
	
    q = inp[1]
    X = inp[2::3]
    Y = inp[3::3]
    REP = inp[4::3]
    A = np.zeros(n, dtype=np.int64)
    tmp = 1
    for i in range(n - 1, -1, -1):
        A[i] = (tmp << 32) + tmp
        tmp *= 10
        tmp %= MOD

    build(A)

    ans = np.zeros(q, dtype=np.int64)
    for i in range(q):
        range_apply(X[i] - 1, Y[i], REP[i])
        ans[i] = all_prod() >> 32

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

from my_module import solve

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print("\n".join(map(str, ans)))