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 PyPy3 (7.3.0) (judge verdict: Time Limit Exceeded)

def main():
    import sys
    input = sys.stdin.buffer.readline
    N, Q = map(int, input().split())
    # N: 処理する区間の長さ
    INF = 2**31-1
    LV = (N-1).bit_length()
    N0 = 2**LV
    data = [0]*(2*N0)
    lazy = [None]*(2*N0)
    mod = 998244353

    modv = [0]*N0*2
    modv[N0+N-2] = 1

    for i in range(N-1):
        modv[N0+N-3-i] = (modv[N0+N-2-i]*10) % mod
    # print(modv)
    for i in range(N0-2, -1, -1):
        modv[i] = (modv[2*i+1] + modv[2*i+2]) % mod

    def gindex(l, r):
        L = (l + N0) >> 1
        R = (r + N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1
            R >>= 1

    # 遅延伝搬処理

    def propagates(*ids):
        for i in reversed(ids):
            v = lazy[i-1]
            if v is None:
                continue
            lazy[2*i-1] = lazy[2*i] = v
            # data[2*i-1] = data[2*i] = v * modv[2*i-1] % mod
            data[2*i-1] = v*modv[2*i-1] % mod
            data[2*i] = v*modv[2*i] % mod
            # print(data)
            lazy[i-1] = None

    # 区間[l, r)をxに更新

    # print(modv)

    def update(l, r, x):
        *ids, = gindex(l, r)
        propagates(*ids)

        L = N0 + l
        R = N0 + r
        v = x
        while L < R:
            if R & 1:
                R -= 1
                lazy[R-1] = v
                data[R-1] = v * modv[R-1] % mod
            if L & 1:
                lazy[L-1] = v
                data[L-1] = v * modv[L-1] % mod
                L += 1
            L >>= 1
            R >>= 1
        for i in ids:
            data[i-1] = (data[2*i-1] + data[2*i]) % mod

    # 区間[l, r)内の合計を求める

    def query(l, r):
        propagates(*gindex(l, r))
        # print(data)
        L = N0 + l
        R = N0 + r

        s = 0
        while L < R:
            if R & 1:
                R -= 1
                s += data[R-1]
            if L & 1:
                s += data[L-1]
                L += 1
            L >>= 1
            R >>= 1
            s %= mod
        return s

    update(0, N, 1)

    for i in range(Q):
        l, r, d = map(int, input().split())
        update(l-1, r, d)
        print((query(0, N) % mod))


main()