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 Go (1.14.1) (judge verdict: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 998244353

func main() {
	var n, q int
	fmt.Scan(&n, &q)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	const block = 2
	bn := ((n - 1) / block) + 1

	ns := make([][]int, 10)
	for i := 1; i <= 9; i++ {
		ns[i] = make([]int, block+1)
		var k int
		for j := 1; j <= block; j++ {
			k = k*10 + i
			k %= mod
			ns[i][j] = k
		}
	}

	sum := make([]int, bn)
	for i := range sum {
		if i == bn-1 {
			sum[i] = ns[1][(n-1)%block+1]
		} else {
			sum[i] = (ns[1][block] * modpow(10, n-(i+1)*block)) % mod
		}
	}
	det := make([][]int, bn)
	for i := range det {
		dn := block
		if i == bn-1 {
			dn = (n-1)%block + 1
		}
		det[i] = make([]int, dn)
		for j := range det[i] {
			det[i][j] = 1
		}
	}

	for i := 0; i < q; i++ {
		sc.Scan()
		l, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		r, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		d, _ := strconv.Atoi(sc.Text())
		l--
		r--

		lb := l / block
		rb := r / block
		if lb == rb {
			b := lb
			for j := l % block; j <= r%block; j++ {
				det[b][j] = d
			}
			var us int
			k := 1
			for j := len(det[b]) - 1; j >= 0; j-- {
				us += det[b][j] * k
				us %= mod
				k *= 10
				k %= mod
			}
			if b != bn-1 {
				us = (us * modpow(10, n-(b+1)*block)) % mod
			}
			sum[b] = us
		} else {
			for j := l % block; j < block; j++ {
				det[lb][j] = d
			}
			for j := 0; j <= r%block; j++ {
				det[rb][j] = d
			}
			for b := range []int{lb, rb} {
				var us int
				k := 1
				for j := len(det[b]) - 1; j >= 0; j-- {
					us += det[b][j] * k
					us %= mod
					k *= 10
					k %= mod
				}
				if b != bn-1 {
					us = (us * modpow(10, n-(b+1)*block)) % mod
				}
				sum[b] = us
			}
			for j := lb + 1; j <= rb-1; j++ {
				sum[j] = (ns[j][block] * modpow(10, n-(j+1)*block)) % mod
			}
		}
		var ans int
		for j := range sum {
			ans += sum[j]
			ans %= mod
		}
		fmt.Println(ans)
	}
}

func modpow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 > 0 {
			res *= a
			res %= mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}