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)

/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Replace Digits
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int MOD = 998244353;

/* typedef */

typedef long long ll;

struct Elm {
  int v, b, t;
  Elm() {}
  Elm(int _v, int _b, int _t): v(_v), b(_b), t(_t) {}

  void set(int d) { v = (ll)d * b % MOD; }

  Elm operator+(const Elm &e) const {
    return
      Elm(((ll)v * e.t % MOD + e.v) % MOD,
	  ((ll)b * e.t % MOD + e.b) % MOD,
	  (ll)t * e.t % MOD);
  }
};

template <typename T, const int MAX_E2>
struct SegTreeDelay {
  int e2;
  T nodes[MAX_E2], defv;
  int dls[MAX_E2];
  SegTreeDelay() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, defv);
    //fill(dls, dls + MAX_E2, 0);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }
  void set(int i, T v) { get(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
  }

  void __update(int k) {
    if (dls[k] > 0) {
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0].set(dls[k]);
      nodes[k1].set(dls[k]);
      dls[k0] = dls[k1] = dls[k];
      dls[k] = 0;
    }
  }

  void set_range(int r0, int r1, int v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k].set(v);
      dls[k] = v;
      return;
    }

    __update(k);

    int im = (i0 + i1) / 2;
    int k0 = k * 2 + 1, k1 = k0 + 1;
    set_range(r0, r1, v, k0, i0, im);
    set_range(r0, r1, v, k1, im, i1);
    nodes[k] = nodes[k0] + nodes[k1];
  }
  void set_range(int r0, int r1, int v) { set_range(r0, r1, v, 0, 0, e2); }

  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    __update(k);

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

SegTreeDelay<Elm,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  st.init(n, Elm(0, 1, 10));

  for (int i = 0; i < n; i++) st.set(i, Elm(1, 1, 10));
  st.setall();

  while (q--) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    l--;

    st.set_range(l, r, d);
    Elm e = st.sum_range(0, n);
    printf("%d\n", e.v);
  }
  return 0;
}