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) (judge verdict: Wrong Answer)

#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define read(a) scanf("%d", &a)
#define readf(a) scanf("%lf", &a)
#define readl(a) scanf("%lld", &a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 1e6 + 7;
const ll mod = 998244353;
int n, q, block, num;
ll fact[N], infact[N];
int L[N], R[N], pos[N];
ll sum[N], add[N], add1[N], a[N];
ll ans = 0;
void build()
{
    block = sqrt(n);
    num = block;
    for(int i = 1; i <= num; i++)
    {
        L[i] = (i - 1) * block + 1;
        R[i] = i * block;
    }
    R[num] = n;
    for(int i = 1; i <= num; i++)
    {
        for(int j = L[i]; j <= R[i]; j++)
        {
            a[j] = 1;
            pos[j] = i;
            add[j] = 0;
            sum[i] = (sum[i] + fact[j]) % mod;
        }
        ans = (ans + sum[i]) % mod;
    }
}
void change(int l, int r, ll k)
{
    int p = pos[l];
    int q = pos[r];
    if(p == q)
    {
        ans -= sum[p];
        ans = (ans % mod + mod) % mod;
        for(int i = l; i <= r; i++)
        {
            if(add[p] != add1[i])
            {
                a[i] = add[p];
                add1[i] = add[p];
            }
            ll d = k - a[i];
            sum[p] = sum[p] + (d * fact[i]);
            sum[p] = (sum[p] % mod + mod) % mod;
            a[i] = k;
        }
        ans = ans + sum[p];
        ans = (ans % mod + mod) % mod;
    }
    else
    {
        ans = ans - sum[p];
        ans = (ans % mod + mod) % mod;
        for(int i = l; i <= R[p]; i++)
        {
            if(add[p] != add1[i])
            {
                a[i] = add[p];
                add1[i] = add[p];
            }
            ll d = k - a[i];
            sum[p] = sum[p] + (d * fact[i]);
            sum[p] = (sum[p] % mod + mod) % mod;
            a[i] = k;
        }
        ans = ans + sum[p];
        ans = (ans % mod + mod) % mod;
        for(int i = p + 1; i <= q - 1; i ++)
        {
            add[i] = k;
            ans -= sum[i];
            ans = (ans % mod + mod) % mod;
            sum[i] = ((infact[R[i]] - infact[L[i] - 1]) % mod + mod) % mod * k;
            sum[i] = (sum[i] % mod + mod) % mod;
            ans += sum[i];
            ans = (ans % mod + mod) % mod;
        }
        ans = ans - sum[q];
        ans = (ans % mod + mod) % mod;
        for(int i = L[q]; i <= r; i++)
        {
            if(add[p] != add1[i])
            {
                a[i] = add[p];
                add1[i] = add[p];
            }
            ll d = k - a[i];
            sum[q] = sum[q] + (d * fact[i]);
            sum[q] = (sum[q] % mod + mod) % mod;
            a[i] = k;
        }
        ans = ans + sum[q];
        ans = (ans % mod + mod) % mod;
    }
}
signed main()
{
    read(n); read(q);
    fact[n] = 1;
    for(int i = n - 1; i >= 1; i--)
        fact[i] = fact[i + 1] * 10ll % mod;
    for(int i = 2; i <= n; i++)
        infact[i] = (((infact[i] + infact[i - 1]) % mod) + fact[i]) % mod;
    build();
    while(q--)
    {
        int l, r;
        ll d;
        read(l); read(r); readl(d);
        change(l, r, d);
        printf("%lld\n", ans);
    }
    return 0;
}
/**
**/