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 with AC Library v1.1) (judge verdict: Accepted)

#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

static const long long MOD = 998244353;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

void solve(long long N, long long Q, std::vector<long long> &L, std::vector<long long> &R, std::vector<long long> &D) {
	vector<vector<modll>> table(10, vector<modll>(N + 1, 0));
	for (LL i = 1; i <= N; ++i) {
		for (int d = 1; d <= 9; ++d) {
			table[d][i] = table[d][i - 1] * 10 + d;
		}
	}

	set<int> s;
	vector<int> len(N + 1), d(N + 1);
	s.insert(0);
	s.insert(N);
	len[0] = N;
	d[0] = 1;
	modll sum = table[1][N];
	for (LL i = 0; i < Q; ++i) {
		LL ll = L[i];
		LL rr = R[i];
		L[i] = N - 1 - rr;
		R[i] = N - 1 - ll + 1;

		auto it = s.lower_bound(L[i]);
		if (*it > L[i]) {
			auto prev = it;
			--prev;
			int st = *prev;
			int l = len[st];
			int ed = st + l;
			int dd = d[st];
			len[st] = L[i] - st;
			sum -= table[dd][ed];
			sum += table[dd][L[i]];
			if (ed > R[i]) {
				s.insert(R[i]);
				len[R[i]] = ed - R[i];
				d[R[i]] = dd;
				sum += table[dd][ed];
				sum -= table[dd][R[i]];

			}
		}
		while (*it < R[i]) {
			int st = *it;
			int l = len[*it];
			int ed = st + l;
			int dd = d[st];
			it = s.erase(it);
			sum -= table[dd][ed];
			sum += table[dd][st];
			if (st + l <= R[i]) {
				continue;
			}
			s.insert(R[i]);
			len[R[i]] = ed - R[i];
			d[R[i]] = dd;
			sum += table[dd][ed];
			sum -= table[dd][R[i]];
			break;
		}
		s.insert(L[i]);
		len[L[i]] = R[i] - L[i];
		d[L[i]] = D[i];
		sum += table[D[i]][R[i]];
		sum -= table[D[i]][L[i]];

/*
		modll ans = 0;
		for (auto x : s) {
			if (x >= N) break;
			ans += table[d[x]][x + len[x]];
			ans -= table[d[x]][x];
		}
		cout << ans << endl;
*/
		cout << sum << endl;
	}
}

int main() {
    long long N;
	std::cin >> N;
	long long Q;
	std::cin >> Q;
	std::vector<long long> L(Q);
	std::vector<long long> R(Q);
	std::vector<long long> D(Q);
	for (int i = 0; i < Q; i++) {
		std::cin >> L[i]; L[i]--;
		std::cin >> R[i]; R[i]--;
		std::cin >> D[i]; // D[i]--;
	}
	solve(N, Q, L, R, D);
	return 0;
}