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: Accepted)

#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
	
const int maxN = 1 << 19, mod = 998244353;

template <class T1, class T2> inline void addMod(T1& a, T2 b)	{   a = (a + b) % mod;  }
template <class T1, class T2> inline void multMod(T1& a, T2 b)	{   a = a * b % mod;    }

long long qpow(long long a, long long b)
{
    long long ret = 1;
    for (; b!=0; b>>=1)
    {
        if (b & 1)  multMod(ret, a);
        multMod(a, a);
    }
    return ret;
}

map <pair <int, int>, int> M;

long long pref10[maxN], res;
int n;

void modf(int i, int j, int d)
{
	int pi = n-i, pj = n-j;
	long long dx = pref10[pi];
	if (pj != 0)
		addMod(dx, mod - pref10[pj-1]);
	multMod(dx, d);
	addMod(res, dx);
}

void dod(int i, int j, int d)
{
	M[{i, j}] = d;
	modf(i, j, d);
}

void usu(auto it)
{
	modf(it->ft.ft, it->ft.sd, mod - it->sd);
	M.erase(it);
}

void solve()
{	
	int q;
	scanf ("%d%d", &n, &q);
	pref10[0] = 1ll;
	FOR(i, 1, n+3)
		pref10[i] = (pref10[i-1] * 10 + 1ll) % mod;
	dod(1, n, 1);	
	while (q--)
	{
		int i, j, d;
		scanf ("%d%d%d", &i, &j, &d);
		auto it = prev(M.upper_bound(make_pair(i, n+1)));
		int a = it->ft.ft, b = it->ft.sd, t = it->sd;
		
		if (a != i)
			dod(a, i-1, t);
			
		while (it != M.end() and it->ft.sd <= j)
			usu(it++);
			
		if (it != M.end())
		{
			b = it->ft.sd, t = it->sd;
			usu(it);
			dod(j+1, b, t);
		}	
		
		dod(i, j, d);
		printf("%lld\n", res);
	}
}

 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}