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# (.NET Core 3.1.201) (judge verdict: Time Limit Exceeded)

using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;

static class Program
{
    static public void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}

public class Solver
{
    N[] ten;
    N[] one;

    public void Solve()
    {
        int n = (int)rn, q = (int)rn;
        ten = new N[n + 1];
        one = new N[n + 1];
        ten[0] = 1;
        one[0] = 0;
        for(int i = 0; i < n; i++)
        {
            ten[i + 1] = (ten[i] * 10) % mod;
            one[i + 1] = (one[i] * 10 + 1) % mod;
        }
        S unit = new S(1,1);
        S[] v = Enumerable.Repeat(unit, n).ToArray();
        Func<S, S, S> op = (x, y) => new S(x.len + y.len, (x.val * ten[y.len] + y.val) % mod);
        Func<int, S, S> mapping = (f, s) => f == 0 ? s : new S(s.len, one[s.len] * f % mod);
        Func<int, int, int> composition = (l, r) => (l == 0) ? r : l;
        S e = new S(0, 0);
        var seg = new LazySegTree<S, int>(v, op, e, mapping, composition, 0);

        for (int i = 0; i < q; i++)
        {
            int L = (int)rn, R = (int)rn, D = (int)rn;
            seg.apply(L - 1, R, D);
            N ans = seg.prod(0, n).val;
            Write(ans);
        }
    }

    public class S
    {
        public int len { get; set; }
        public N val { get; set; }
        public S(int len, N val)
        {
            this.len = len;
            this.val = val;
        }
    }

    public class LazySegTree<S, F>
    {
        int _n, log, size;
        S _e;
        Func<S, S, S> _op;
        Func<F, S, S> _mapping;
        Func<F, F, F> _composition;
        F _id;
        S[] d;
        F[] lz;
        public LazySegTree(S[] v, Func<S, S, S> op, S e, Func<F, S, S> mapping, Func<F, F, F> composition, F id)
        {
            _op = op;
            _mapping = mapping;
            _composition = composition;
            _id = id;
            _e = e;
            _n = v.Length;
            log = 0;
            while (1 << log < _n) { log++; }
            size = 1 << log;
            d = Enumerable.Repeat(_e, 2 * size).ToArray();
            lz = Enumerable.Repeat(_id, size).ToArray();
            for (int i = 0; i < _n; i++) { d[size + i] = v[i]; }
            for (int i = size - 1; i > 0; i--) { update(i); }
        }
        public void set(int p, S x)
        {
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            d[p] = x;
            for (int i = 1; i <= log; i++) update(p >> i);
        }
        public S get(int p)
        {
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            return d[p];
        }
        public S prod(int l, int r)
        {
            if (l == r) return _e;
            l += size;
            r += size;
            for (int i = log; i >= 1; i--)
            {
                if (((l >> i) << i) != l) push(l >> i);
                if (((r >> i) << i) != r) push(r >> i);
            }
            S sml = _e, smr = _e;
            while (l < r)
            {
                if ((l & 1) == 1) sml = _op(sml, d[l++]);
                if ((r & 1) == 1) smr = _op(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }

            return _op(sml, smr);
        }
        public S all_prod() { return d[1]; }
        public void apply(int p, F f)
        {
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            d[p] = _mapping(f, d[p]);
            for (int i = 1; i <= log; i++) update(p >> i);
        }
        public void apply(int l, int r, F f)
        {
            if (l == r) return;
            l += size;
            r += size;
            for (int i = log; i >= 1; i--)
            {
                if (((l >> i) << i) != l) push(l >> i);
                if (((r >> i) << i) != r) push((r - 1) >> i);
            }
            {
                int l2 = l, r2 = r;
                while (l < r)
                {
                    if ((l & 1) == 1) all_apply(l++, f);
                    if ((r & 1) == 1) all_apply(--r, f);
                    l >>= 1;
                    r >>= 1;
                }
                l = l2;
                r = r2;
            }

            for (int i = 1; i <= log; i++)
            {
                if (((l >> i) << i) != l) update(l >> i);
                if (((r >> i) << i) != r) update((r - 1) >> i);
            }
        }

        void update(int i) { d[i] = _op(d[2 * i], d[2 * i + 1]); }
        void all_apply(int k, F f)
        {
            d[k] = _mapping(f, d[k]);
            if (k < size) lz[k] = _composition(f, lz[k]);
        }
        void push(int k)
        {
            all_apply(2 * k, lz[k]);
            all_apply(2 * k + 1, lz[k]);
            lz[k] = _id;
        }
    }

    const N mod = 998244353;
    N Gcd(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; }
    N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }

    N rn { get { return sc.Integer(); } }
    double rd { get { return sc.Double(); } }
    string rs { get { return sc.Scan(); } }
    public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());

    void Write<T>(T t) { Console.WriteLine(t.ToString()); }
    void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
    void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
    void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}



public class StreamScanner
{
    public StreamScanner(Stream stream) { str = stream; }
    private readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public bool IsEndOfStream { get { return isEof; } }
    private byte read()
    {
        if (isEof) throw new EndOfStreamException();
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
    public char Char()
    {
        byte b = 0;
        do b = read();
        while (b < 33 || 126 < b);
        return (char)b;
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
            sb.Append(b);
        return sb.ToString();
    }
    public N Integer()
    {
        N ret = 0; byte b = 0; var ng = false;
        do b = read();
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-') { ng = true; b = read(); }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
                return ng ? -ret : ret;
            else ret = ret * 10 + b - '0';
        }
    }
    public double Double() { return double.Parse(Scan()); }
}