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.



Sample input:
8 5
3 6 2
1 4 7
3 8 3
2 2 2
4 5 1


Sample output:
11222211
77772211
77333333
72333333
72311333

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(i) for i in input().split()]
S = '1' * N
for i in range(Q):
    tL, tR, tD = [int(i) for i in input().split()]
    L = int(tL) - 1
    R = int(tR) - 1
    D = str(tD)
    len = R - L + 1
    S = S[0:L] + (D * len) + S[R + 1:N]
    print(int(S) % 998244353)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, Q = map(int, input().split())
    S = "1" * N
    for i in range(Q):
        l, r, d = map(int, input().split())
        l -= 1
        r -= 1
        # print(S[:l])
        S = S[:l] + str(d) * (r - l + 1) + S[r + 1 :]
        S = str(int(S) % 998244353)
        print(S)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


class LazySegmentTree():
    def __init__(self, op, e, mapping, composition, im, init_array):
        self.op = op
        self.e = e
        self.mapping = mapping
        self.composition = composition
        self.im = im

        l = len(init_array)

        def ceil_pow2(n):
            x = 0
            while (1 << x) < n:
                x += 1
            return x
        self.log = ceil_pow2(l)
        self.size = 1 << self.log
        self.d = [e() for _ in range(2*self.size)]
        self.lz = [im() for _ in range(self.size)]

        for i, a in enumerate(init_array):
            self.d[i+self.size] = a

        for i in range(self.size-1, 0, -1):
            self.__update(i)

    def set(self, p, x):
        p += self.size

        for i in range(self.log, 0, -1):
            self.__push(p >> i)

        self.d[p] = x

        for i in range(1, self.log+1):
            self.__update(p >> i)

    def __getitem__(self, p):
        p += self.size
        for i in range(self.log, 0, -1):
            self.__push(p >> i)
        return self.d[p]

    def prod(self, l, r):
        if l == r:
            return self.e()

        l += self.size
        r += self.size

        for i in range(self.log, 0, -1):
            if ((l >> i) << i) != l:
                self.__push(l >> i)
            if ((r >> i) << i) != r:
                self.__push(r >> i)

        sml = self.e()
        smr = self.e()

        while l < r:
            if l & 1:
                sml = self.op(sml, self.d[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.d[r], smr)
            l >>= 1
            r >>= 1

        return self.op(sml, smr)

    def apply(self, l, r, f):
        if l == r:
            return

        l += self.size
        r += self.size

        for i in range(self.log, 0, -1):
            if ((l >> i) << i) != l:
                self.__push(l >> i)
            if ((r >> i) << i) != r:
                self.__push((r-1) >> i)

        l2, r2 = l, r
        while l < r:
            if l & 1:
                self.__all_apply(l, f)
                l += 1
            if r & 1:
                r -= 1
                self.__all_apply(r, f)
            l >>= 1
            r >>= 1
        l, r = l2, r2

        for i in range(1, self.log+1):
            if ((l >> i) << i) != l:
                self.__update(l >> i)
            if ((r >> i) << i) != r:
                self.__update((r-1) >> i)

    def __update(self, k):
        self.d[k] = self.op(self.d[2*k], self.d[2*k+1])

    def __all_apply(self, k, f):
        self.d[k] = self.mapping(f, self.d[k])
        if k < self.size:
            self.lz[k] = self.composition(f, self.lz[k])

    def __push(self, k):
        self.__all_apply(2*k, self.lz[k])
        self.__all_apply(2*k+1, self.lz[k])
        self.lz[k] = self.im()


M = 998244353

def e():
    # (v, b)
    return (0, 0)

def op(sl, sr):
    # print(sl, sr)
    return ((sl[0] + sr[0]) % M, (sl[1] + sr[1]) % M)

def mapping(fl, sr):
    if fl[0] == 0:
        return sr
    return ((sr[1]*fl[0]) % M, sr[1])

def composition(fl, fr):
    if fl[1] > fr[1]:
        return fl
    return fr

def im():
    return (0, -1)

@mt
def slv(N, Q, LRQ):
    A = [(pow(10, N-i-1, M), pow(10, N-i-1, M)) for i in range(N)]
    st = LazySegmentTree(op, e, mapping, composition, im, A)

    ans = []
    for i, (l, r, d) in enumerate(LRQ, start=1):
        l -= 1
        st.apply(l, r, (d, i))
        ans.append(st.prod(0, N)[0])
    return ans


def main():
    N, Q = read_int_n()
    LRQ = [read_int_n() for _ in range(Q)]
    print(*slv(N, Q, LRQ), sep='\n')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
mod = 998244353
s_list = [1]*n

s = 0
for i in range(n):
  s += pow(10,i,mod)

for _ in range(q):
  l,r,d = map(int,input().split())
  for i in range(l,r+1):
    s += pow(10,n-i,mod)*(d-s_list[i-1])
  s_list[l-1:r] = [d]*(r-l+1)
  print(s%mod)

Submission status: Time Limit Exceeded

Solution code:
input_data = list(map(int, input().split()))
start_num =[1]*input_data[0]
N = input_data[1]

# print(start_num)
for i in range(N):
    input_val = list(map(int, input().split()))
    standard_num = input_val[1]-input_val[0]+1
    new_num = input_val[2]
    for j in range(standard_num):
        start_num[input_val[0]-1+j] = new_num
    last_num =""
    start_num = list(map(str,start_num))
    for k in range(len(start_num)):
        last_num += start_num[k]
    if i < N-1:
        print(last_num)
    else:
        print(int(last_num)%998244353)
    start_num = list(map(int,start_num))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = "1" * n
ans = []
for i in range(q):
    l,r,d = map(int, input().split())
    a = s[:l-1] + str(d)*(r-l+1) + s[r:]
    s = a
    ans.append(int(a) % 998244353)
for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
LRD = [list(map(int,input().split())) for _ in range(Q)]

MOD = 998244353
S = '1' * N
for L,R,D in LRD:
    S = S[:L-1] + str(D) * (R-L+1) + S[R:]
    ans = int(S)
    print(ans%MOD)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
N_list = [1]* N
num_list = []
temp = 0
num = 0
num_mod = 0
for i in range(Q):
    num_list.append(list(map(int, input().split())))
for j in range(Q):
    keta = 1
    for k in range(num_list[j][0]-1, num_list[j][1]):
        N_list[k] = num_list[j][2]
        #print(N_list)
    num = 0
    temp = 0
    for l in range(N):
        temp = N_list[N-l-1] * keta
        num += temp
        keta *= 10
    num_mod = num % 998244353
    print(num_mod)

Submission status: Time Limit Exceeded

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abl/abl_e
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

P = 998_244_353

ONES = [0] * 200_001
for i in range(1, 200_001):
    ONES[i] = (ONES[i-1] + pow(10, i - 1, P)) % P

def main():
    N, Q = i2nn()
    S = '1' * N
    A = ONES[N]
    for _ in range(Q):
        L, R, D = i2nn()
        if R - L < N / 2:
            T = S[L-1:R]
            digi = pow(10, N - R, P)
            B = ((int(T) % P) * digi) % P
            C = (ONES[R - L + 1] * D * digi) % P
            A = (A - B + C) % P
        else:
            RB = int(S[R:]) % P if R < N else 0
            LB = ((int(S[:L-1]) % P) * pow(10, N-L+1, P)) % P if L-1 > 0 else 0
            B = (RB + LB) % P
            C = (ONES[R - L + 1] * D * pow(10, N - R, P)) % P
            A = (B + C) % P
        print(A)
        S = f'{S[:L-1]}{str(D)*(R-L+1)}{S[R:]}'
    return

main()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = "1" * n
ans = []
for i in range(q):
    l,r,d = map(int, input().split())
    for j in range(l-1,r):
        a = s[:l-1] + str(d)*(r-l+1) + s[r:]
    s = a
    ans.append(int(a) % 998244353)
for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
# MOD = 10 ** 9 + 7
MOD = 998244353
num_list = []
str_list = []

def main():
    n, q = i_map()

    ans = '1' * n

    for _ in range(q):
        ans = list(ans)
        l, r, d = i_map()
        ans[l-1:r] = str(d) * (r - l + 1)
        ans = "".join(ans)
        print(int(ans)%MOD)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
input_data = list(map(int, input().split()))
start_num =[1]*int(input_data[0])
N = input_data[1]

# print(start_num)
for i in range(N):
    input_val = list(map(int, input().split()))
    standard_num = input_val[1]-input_val[0]+1
    new_num = input_val[2]
    for j in range(standard_num):
        start_num[input_val[0]-1+j] = new_num
    last_num =""
    start_num = list(map(str,start_num))
    for k in range(len(start_num)):
        last_num += start_num[k]
    if i == N-1:
        print(int(last_num)%998244353)
    else:
        print(last_num)
    start_num = list(map(int,start_num))

Submission status: Time Limit Exceeded

Solution code:
MOD = 998244353

N, Q = map(int, input().split())
a = [1] * N

for _ in range(Q):
    l, r, d = map(int, input().split())
    for i in range(l-1, r):
        a[i] = d

    ans = 0
    for i in range(N):
        ans = (ans * 10 + a[i]) % MOD

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n,q=map(int,input().split())
  s=["1"]*n
  r0=int("".join(s))%  998244353
  #print(r0)
  for i in range(q):
    l,r,d=map(int,input().split())
    l=l-1
    lr=r-l
    #print(s[l:r])
    #print([str(d)]*lr)
    s1=s[l:r]
    s2=[str(d)]*lr
    r1=int("".join(s1))
    r2=int("".join(s2))
    r21=r2-r1
    w=n-r
    if w<=9:
      #print(r21*(10**w) )
      if r21>=0:
        plu=r21*(10**w)  %  998244353
        r0 +=plu
        r0 %= 998244353
      else:
        plu=(0-r21)*(10**w)  %  998244353
        r0 +=(998244353 -plu)
        r0 %= 998244353
    else:
      if r21>=0:
        plu=r21*((10**9-998244353)**(w//9))*(10**(w%9))  %  998244353
        r0 +=plu
        r0 %= 998244353
      else:
        plu=(0-r21*((10**9-998244353)**(w//9))*(10**(w%9)))  %  998244353
        r0 +=(998244353 -plu)
        r0 %= 998244353
    print(r0)
    s[l:r]=s2
main()

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = "1"*n
for i in range(q):
    L, R, D = list(map(int, input().split()))
    s = s[:(L-1)] + str(str(D)*(R-L+1)) + s[R:]
    print(divmod(int(s), 998244353)[1])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
LRD = [list(map(int, input().split())) for _ in range(Q)]

mod = 998244353

l = []
t = ''
for i in range(100000):
    t += '1'
for i in range(1, 10):
    l.append(str(int(t) * i))

S = ''
for i in range(N):
    S += '1'

for i in range(Q):
    t = l[LRD[i][2] - 1]
    while len(t) < LRD[i][1] - LRD[i][0] + 1:
        t += t
    S = S[:LRD[i][0] - 1] + t[:LRD[i][1] - LRD[i][0] + 1] + S[LRD[i][1]:]
    print(int(S) % mod)

Submission status: Time Limit Exceeded

Solution code:
MOD = 998244353 
X, Y = 500, 400
n, q = map(int, input().split())

re = [[pow(10, X * i + j, MOD) for j in range(X)] for i in range(Y)]
ra = [0 for _ in range(Y)]
for i in range(Y):
     for j in range(X):
         ra[i] += re[i][j]

ans = 0
se = [[0 for _ in range(X)] for _ in range(Y)]
sa = [0 for _ in range(Y)]
for i in range(Y):
    for j in range(X):
        if i * X + j < n:
            ans += re[i][j]
            ans %= MOD
            se[i][j] = re[i][j]
            sa[i] += re[i][j]
            sa[i] %= MOD

de = [[0 for _ in range(X)] for _ in range(Y)]
for i in range(Y):
    for j in range(X):
        if i * X + j < n:
            de[i][j] = 1

for _ in range(q):
    l, r, d = map(int, input().split())
    l, r = n - r, n - l
    for i in range(l // X, r // X + 1):
        if l <= X * i and X * i + X - 1 <= r:
            ans -= sa[i]
            sa[i] = ra[i] * d % MOD
            ans += sa[i]
            ans %= MOD
        else:
            for j in range(X):
                if l <= X * i + j <= r:
                    ans -= se[i][j]
                    sa[i] -= se[i][j]
                    se[i][j] = re[i][j] * d % MOD
                    sa[i] += se[i][j]
                    ans += se[i][j] 
                    ans %= MOD
                    sa[i] %= MOD
                    de[i][j] = d
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
def binary(n):
    return bin(n)[2:]
def bjy(a, x, n): # a^x mod n
    if x==0:
      return 1
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y
tab=[]
mod=998244353
out=0
for i in range(n):
  jy=bjy(10,i,mod)
  tab.append(jy)
  out+=jy
  out%=mod
num=[1]*n
for i in range(q):
  l,r,d=map(int,input().split())
  l-=1
  r-=1
  for j in range(l,r+1):
    chan=d-num[j]
    out+=(tab[n-j-1]*chan)
    out%=mod
    num[j]=d
  print(out)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
num = '1'*N
MOD = 998244353
for _ in range(Q):
  L, R, Q = input().split()
  L = int(L)
  R = int(R)
  sub = Q*(R-L+1)
  num = num[:L-1] + sub + num[R:]
  print(int(num)%MOD)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
readline = stdin.readline

def main():
  n,q = map(int, readline().split())
  mod = 998244353
  tmp = [1] * n

  for i in range(q):
    l,r,d = map(int, readline().split())
    tmp[l-1:r] = [d] * (r-l+1)
    tmp_str = map(str, tmp)
    print(int(''.join(tmp_str)) % mod)

main()

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = ["1"] * N

#def str_join(args):
#    return ''.join(map(str, args))

ones = int(''.join(S))#int(str_join(S))
S_tmp = ones
S_mod = S_tmp % 998_244_353
  
for _ in range(Q):
  L, R, D = map(int, input().split())
  
  #tmp = 0
  #for i in range(L - 1, R):
  #  tmp += D * (10 ** (N - i + 1))
    
  left = 10 ** (N - L + 1)
  right = 10 ** (N - R)
  S = (S_tmp // left) * left
  S += S_tmp % right
  
  S_old = S_tmp % left
  S_old = S_old - S_old % right
  S_old_mod = S_old % 998_244_353
  
  tmp = ones * D
  tmp = tmp % left
  tmp = tmp - tmp % right
  S_new_mod = tmp % 998_244_353
  S_mod = (S_mod - S_old_mod + S_new_mod) % 998_244_353
  S_tmp = S + tmp
  
  #S += tmp
  #res_mod = (S_tmp - tmp) % 998_244_353
  #S_mod = S_mod + res_mod
  print(S_mod)
  
  
  #_S = str_join(S)
  #print(S % 998_244_353)
  #S_tmp = S

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s="1"*n
one="1"*200000
two="2"*200000
three="3"*200000
four="4"*200000
five="5"*200000
six="6"*200000
seven="7"*200000
eight="8"*200000
nine="9"*200000

for i in range(q):
  l,r,d=map(int,input().split())
  if d==1:
    s=s[:l-1]+one[:r-l+1]+s[r:]
  elif d==2:
    s=s[:l-1]+two[:r-l+1]+s[r:]
  elif d==3:
    s=s[:l-1]+three[:r-l+1]+s[r:]
  elif d==4:
    s=s[:l-1]+four[:r-l+1]+s[r:]
  elif d==5:
    s=s[:l-1]+five[:r-l+1]+s[r:]
  elif d==6:
    s=s[:l-1]+six[:r-l+1]+s[r:]
  elif d==7:
    s=s[:l-1]+seven[:r-l+1]+s[r:]
  elif d==8:
    s=s[:l-1]+eight[:r-l+1]+s[r:]
  elif d==9:
    s=s[:l-1]+nine[:r-l+1]+s[r:]
  print(int(s)%998244353)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
LRD = [list(map(int, input().split())) for _ in range(Q)]

mod = 998244353

l = []
t = ''
for i in range(20000):
    t += '1'
for i in range(1, 10):
    l.append(str(int(t) * i))

S = ''
for i in range(N):
    S += '1'

for i in range(Q):
    t = l[LRD[i][2] - 1]
    while len(t) < LRD[i][1] - LRD[i][0] + 1:
        t += t
    S = S[:LRD[i][0] - 1] + t[:LRD[i][1] - LRD[i][0] + 1] + S[LRD[i][1]:]
    print(int(S) % mod)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = [str(1)]*N
L = []*Q
R = []*Q
D = []*Q
for i in range (Q):
  a,b,c = map(int,input().split())
  L.append(a)
  R.append(b)
  D.append(c)
for i in range (Q):
  S[L[i]-1:R[i]] = [str(D[i])]*(R[i]-L[i]+1)
  Smap = map (str,S)
  Sstr = "".join(Smap)
  Sint = int(Sstr)
  ans = Sint % 998244353
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

moe = 998244353

n,q = I()
num = []
a = "1"*n

for i in range(q):
    l,r,d = I()
    leng = r-l+1
    a = a[:l-1]+str(d)*leng+a[r:]
    num.append(a)
    
for i in num:
    print(int(i)%moe)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())

A = "1" * N

for i in range(Q):
  l, r, d = map(int, input().split())
  A = A[:l - 1] + str(d) * (r - l + 1) + A[r:]
  out = int(A) % 998244353
  print(out)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
LRD = [list(map(int, input().split())) for _ in range(Q)]

mod = 998244353

l = []
t = ''
for i in range(20000):
    t += '1'
for i in range(1, 10):
    l.append(str(int(t) * i))

S = ''
for i in range(N):
    S += '1'

for i in range(Q):
    Sn = S[:LRD[i][0] - 1]
    t = l[LRD[i][2] - 1]
    while len(t) < LRD[i][1] - LRD[i][0] + 1:
        t += t
    Sn += t[:LRD[i][1] - LRD[i][0] + 1]
    Sn += S[LRD[i][1]:]
    S = S[:LRD[i][0] - 1] + t[:LRD[i][1] - LRD[i][0] + 1] + S[LRD[i][1]:]
    print(int(S) % mod)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
mod=998244353
s=[pow(10,n-i-1,mod) for i in range(n)]
for _ in range(q):
    l,r,d=map(int,input().split())
    s[l-1:r]=[pow(10,n-i-1,mod)*d for i in range(l-1,r)]
    print(sum(s)%mod)

Submission status: Time Limit Exceeded

Solution code:
n, q = (int(x) for x in input().split())


s = ""
for a in range(n):
  s = s + "1"

for j in range(q):
  a, b, c = (int(x) for x in input().split())

  s2 = s[:a-1]
  s3 = s[b:]

  for i in range(b-a+1):
    s2 = s2 + str(c)
  
  s = s2 + s3

  print(int(s) % 998244353)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
mod=998244353
s="".join(["1"]*n)
for i in range(q):
  l,r,d=input().split()
  l,r=int(l),int(r)
  s=s[0:l-1]+d*(r-l+1)+s[r:]
  s=str(int(s)%mod)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = "1" * n

for i in range(q) :
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    L = []
    L.append(s[0:l])
    L.append(str(d) * (r-l+1))
    L.append(s[r+1:n])
    s = ''.join(L)
    print(int(s) % 998244353)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    X=list(map(int,input().split()))
    N=X[0]
    Q=X[1]
    LRD=[list(map(int,input().split())) for _ in range(Q)]
    S=0
    ss=0
    mod=998244353
    S=(10**N-1)//9
    for x in LRD:
        L=S-S%(10**(N-x[0]+1))
        R=S%(10**(N-x[1]))
        ss=(10**(x[1]-x[0]+1)-1)//9
        D=x[2]*ss*(10**(N-x[1]))
        ss=0
        S=L+R+D
        print(S%mod)
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline()


def solve():
    def init(init_arr):
        global num, segfunc, ide_ele, seg
        segfunc = lambda x, y: y
        ide_ele = 0
        num = 2 ** (n - 1).bit_length()
        seg = [ide_ele] * 2 * num
        for i in range(n):
            seg[i + num - 1] = init_arr[i]
        for i in range(num - 2, -1, -1):
            seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k - 1) // 2
            seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = segfunc(res, seg[p])
            if q & 1 == 1:
                res = segfunc(res, seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

    n, q = map(int, input().split())
    a = [1] * n

    init(a)

    for _ in range(q):
        l, r, rep = map(int, input().split())
        for i in range(l - 1, r):
            update(i, rep)
        ans = []
        for i in range(n):
            ans.append(query(i, i + 1))
        print(int("".join(map(str, ans))) % 998244353)
solve()

Submission status: Time Limit Exceeded

Solution code:
PRIME = 998244353
n, q = map(int, input().split())
s = '1' * n

ones = []
tmp = 0
for i in range(n):
  tmp = (tmp * 10 + 1) % PRIME
  ones.append(tmp)

for i in range(q):
  l, r, d = map(int, input().split())
  ans = 0
  if l > 1:
    ans += int(s[:(l - 1)]) * pow(10, n - l + 1, PRIME) 
    ans %= PRIME
  if r < n:
    ans += int(s[r:])
    ans %= PRIME
  ans %= PRIME
  ans += ones[r - l] * d * pow(10, n - r, PRIME)
  ans %= PRIME
  print(ans)
  s = s[:(l - 1)] + str(d) * (r - l + 1) + s[r:]

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(i) for i in input().split()]
mod = 998244353
S = "1"*N
Sl = list(S)
#print(Sl)
for i in range(Q):
    L,R,D = [int(i) for i in input().split()]
    for j in range(L-1,R):
        Sl[j] = str(D)
    print(int("".join(Sl))%mod)

Submission status: Time Limit Exceeded

Solution code:
#e
n,q = map(int, input().split())
s = "1"*n
mod = 998244353

before = s
before_m = int(s)%mod

for i in range(q):
    l,r,d = map(int, input().split())
    s = s[:l-1] + str(d)*(r-l+1) +s[r:]
    
    dif = int(s) - int(before)
    
    if dif < 0:
        ans = (before_m+dif+mod)%mod
        print(ans)
    else:
        ans = (before_m+dif)%mod
        print(ans)
    
    before = s
    before_m = ans

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
L = [list(map(int, input().split())) for i in range(Q)]

S = '1' * N

for i in range(Q):
    left_S = S[:(L[i][0] - 1)]
    right_S = S[L[i][1]:]
    center_S = str(L[i][2]) * (L[i][1] - L[i][0] + 1)
    S = left_S + center_S + right_S
    print(int(S) % 998244353)

Submission status: Time Limit Exceeded

Solution code:
n,q=[int(x) for x in input().split()]
ans = "1"*n
for i in range(q):
  l,r,d=[int(x) for x in input().split()]
  ans = ans[0:l-1] + str(d)*(r-l+1) + ans[r:]
  print(int(ans)%998244353)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
num='1'*N

for _ in range(Q):
    L,R,D=map(int,input().split())
    D=str(D)
    num=num[:L-1]+D*(R-L+1)+num[R:]
    ans=int(num)%998244353
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
mod = 998244353
n, q = map(int, input().split())
s = np.ones(n)
for _ in range(q):
  l, r, d = map(int, input().split())
  s[l-1:r] = d
  print(int("".join(s.astype(int).astype(str))) % mod)

Submission status: Time Limit Exceeded

Solution code:
n , q = map(int, input().split())
string = "1"*n
for i in range(q):
  l, r, d = map(int, input().split())
  string = "".join([string[:l-1], str(d)*(r-l+1), string[r:]])
  print((int("".join(string)))%998244353)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
mod = 998244353
tmp = [1] * n

for i in range(q):
  l,r,d = map(int, input().split())
  tmp[l-1:r] = [d] * (r-l+1)
  tmp_str = map(str, tmp)
  print(int(''.join(tmp_str)) % mod)