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)

#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 998244353;

ll p[maxn];
ll sp[maxn];
struct ST {
  int l,r,d;
  ll val;
}st[maxn*4];
void up(int id){
  st[id].val = (st[id<<1].val * p[st[id<<1|1].r-st[id<<1|1].l+1]%mod + st[id<<1|1].val)%mod;
}
void build(int id, int l, int r){
  st[id].l=l,st[id].r=r,st[id].d = 0, st[id].val = 0;
  if(l==r){
    st[id].d = 1;
    st[id].val = 1;
    return;
  }
  int m = (l+r)>>1;
  build(id<<1,l,m);
  build(id<<1|1,m+1,r);
  up(id);
}
void down(int id){
  if(!st[id].d)return;
  int d = st[id].d;
  st[id].d = 0;
  st[id<<1].d = d;
  st[id<<1].val = sp[st[id<<1].r-st[id<<1].l]*d%mod;
  st[id<<1|1].d = d;
  st[id<<1|1].val = sp[st[id<<1|1].r-st[id<<1|1].l]*d%mod;
}
void add(int id, int l, int r, int val){
  if(st[id].l==l&&st[id].r==r){
    st[id].d = val;
    st[id].val = sp[r-l] * val % mod;

    return;
  }
  down(id);
  int m = (st[id].l+st[id].r)>>1;
  if(r<=m)add(id<<1,l,r,val);
  else if(l>m)add(id<<1|1,l,r,val);
  else {
    add(id<<1,l,m,val);
    add(id<<1|1,m+1,r,val);
  }
  up(id);
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,q;
  cin>>n>>q;
  p[0] = 1, sp[0] = 1;
  for(int i=1;i<maxn;i++){
    p[i] = p[i-1]*10%mod;
    sp[i] = (sp[i-1] + p[i])%mod;
  }
  build(1,1,n);
  while(q--){
    int l,r,d;
    cin>>l>>r>>d;
    add(1,l,r,d);
    cout<<st[1].val<<endl;
  }
  return 0;
}