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)

#include<bits/stdc++.h>
#include <complex>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace  std;

#define ll long long
#define ull unsigned long long
#define f first
#define s second
typedef pair<int , int > pii;
typedef pair<ll,ll> pll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

const ll MOD = 998244353 ;

void min_self(ll &a , ll b){a=min(a,b);}
void max_self(ll &a, ll b){a=max(a,b);}
ll add(ll x, ll y){return (x + y) % MOD;}
ll sub(ll x, ll y){return add(x, MOD - y);}
ll mul(ll x, ll y){return (x * 1ll * y) % MOD;}
ll binpow(ll x, ll y)
{   ll z = 1;
    while(y > 0)
    {if(y % 2 == 1) z = mul(z, x);
        x = mul(x, x);
        y /= 2;
    }
    return z;
}
ll inv(ll x){return binpow(x, MOD - 2);}
const int MXN = 1e6+10;
ll fact[MXN];
void fac_pre()
{
    fact[0]=1;
    for(ll i=1; i<MXN; i++){
        fact[i]=mul(fact[i-1],i);
    }
}
ll C(ll n, ll k)
{   if(n<0 || k<0) return 0;
    if(k>n) return 0;
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
///--//

// Change lazy updates as per requirement
struct dat
{
    //Use required attributes
    int val;

    //Default Values
    dat() : val(0) {};
    int get_val(){
        return val;
    }
};

struct SegTree
{
    int N;
    vector<dat> st;
    vector<bool> cLazy;
    vector<int> lazy;
    vector<int> m_pow;
    vector<int> cof;
    void init(int n)
    {
        N = n;
        st.resize(4 * N + 5);
        cLazy.assign(4 * N + 5, false);
        lazy.assign(4 * N + 5, 0);
        cof.assign(4*N+5,0);
        m_pow.assign(N+5,0);
        m_pow[n]=1;
        for(int i=n-1; i>=1; i--){
            m_pow[i]=mul(m_pow[i+1],10);
        }
    }

    //Write reqd merge functions
    void merge(dat &cur, dat &l, dat &r)
    {
        cur.val=add(l.val,r.val);
    }

    //Handle lazy propagation appriopriately
    void propagate(int node, int L, int R)
    {
        if(L != R)
        {
            cLazy[node*2] = 1;
            cLazy[node*2 + 1] = 1;
            lazy[node*2] = lazy[node];
            lazy[node*2 + 1] = lazy[node];
        }
        st[node].val = mul(cof[node],lazy[node]);
        cLazy[node] = 0;
    }

    void build(int node, int L, int R)
    {
        if(L==R)
        {
            cof[node]=m_pow[L];
            st[node].val = m_pow[L];
            return;
        }
        int M=(L + R)/2;
        build(node*2, L, M);
        build(node*2 + 1, M + 1, R);
        cof[node]=add(cof[node*2],cof[node*2+1]);
        merge(st[node], st[node*2], st[node*2+1]);
    }

    dat Query(int node, int L, int R, int i, int j)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return dat();
        if(i<=L && R<=j)
            return st[node];
        int M = (L + R)/2;
        dat left=Query(node*2, L, M, i, j);
        dat right=Query(node*2 + 1, M + 1, R, i, j);
        dat cur;
        merge(cur, left, right);
        return cur;
    }


    void Update(int node, int L, int R, int i, int j, int val)
    {
        if(cLazy[node])
            propagate(node, L, R);
        if(j<L || i>R)
            return;
        if(i<=L && R<=j)
        {
            cLazy[node] = 1;
            lazy[node] = val;
            propagate(node, L, R);
            return;
        }
        int M = (L + R)/2;
        Update(node*2, L, M, i, j, val);
        Update(node*2 + 1, M + 1, R, i, j, val);
        merge(st[node], st[node*2], st[node*2 + 1]);
    }


    dat query(int l, int r)
    {
        return Query(1, 1, N, l, r);
    }



    void update(int l, int r, int val)
    {
        Update(1, 1, N, l, r, val);
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen ("output.txt","w",stdout);
    /* KEEP IN MIND
     * take care when sorting a 1 based indexed vector
     * use greater<ll> for ll's
    */

    
    int n,q; cin>>n>>q;
    SegTree st;
    st.init(n);
    st.build(1,1,n+1);
    while(q--){
        int l,r,d; cin>>l>>r>>d;
        st.update(l,r,d);
        int ans=st.query(1,n).get_val();
        cout<<ans<<endl;
    }
    return 0;


}