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:
import typing

def _ceil_pow2(n: int) -> int:
    x = 0
    while (1 << x) < n:
        x += 1

    return x


def _bsf(n: int) -> int:
    x = 0
    while n % 2 == 0:
        x += 1
        n //= 2

    return x

class LazySegTree:
    def __init__(
            self,
            op: typing.Callable[[typing.Any, typing.Any], typing.Any],
            e: typing.Any,
            mapping: typing.Callable[[typing.Any, typing.Any], typing.Any],
            composition: typing.Callable[[typing.Any, typing.Any], typing.Any],
            id_: typing.Any,
            v: typing.Union[int, typing.List[typing.Any]]) -> None:
        self._op = op
        self._e = e
        self._mapping = mapping
        self._composition = composition
        self._id = id_

        if isinstance(v, int):
            v = [e] * v

        self._n = len(v)
        self._log = _ceil_pow2(self._n)
        self._size = 1 << self._log
        self._d = [e] * (2 * self._size)
        self._lz = [self._id] * self._size
        for i in range(self._n):
            self._d[self._size + i] = v[i]
        for i in range(self._size - 1, 0, -1):
            self._update(i)

    def set(self, p: int, x: typing.Any) -> None:
        assert 0 <= p < self._n

        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 get(self, p: int) -> typing.Any:
        assert 0 <= p < self._n

        p += self._size
        for i in range(self._log, 0, -1):
            self._push(p >> i)
        return self._d[p]

    def prod(self, left: int, right: int) -> typing.Any:
        assert 0 <= left <= right <= self._n

        if left == right:
            return self._e

        left += self._size
        right += self._size

        for i in range(self._log, 0, -1):
            if ((left >> i) << i) != left:
                self._push(left >> i)
            if ((right >> i) << i) != right:
                self._push(right >> i)

        sml = self._e
        smr = self._e
        while left < right:
            if left & 1:
                sml = self._op(sml, self._d[left])
                left += 1
            if right & 1:
                right -= 1
                smr = self._op(self._d[right], smr)
            left >>= 1
            right >>= 1

        return self._op(sml, smr)

    def all_prod(self) -> typing.Any:
        return self._d[1]

    def apply(self, left: int, right: typing.Optional[int] = None,
              f: typing.Optional[typing.Any] = None):
        assert f is not None

        if right is None:
            p = left
            assert 0 <= left < self._n

            p += self._size
            for i in range(self._log, 0, -1):
                self._push(p >> i)
            self._d[p] = self._mapping(f, self._d[p])
            for i in range(1, self._log + 1):
                self._update(p >> i)
        else:
            assert 0 <= left <= right <= self._n
            if left == right:
                return

            left += self._size
            right += self._size

            for i in range(self._log, 0, -1):
                if ((left >> i) << i) != left:
                    self._push(left >> i)
                if ((right >> i) << i) != right:
                    self._push((right - 1) >> i)

            l2 = left
            r2 = right
            while left < right:
                if left & 1:
                    self._all_apply(left, f)
                    left += 1
                if right & 1:
                    right -= 1
                    self._all_apply(right, f)
                left >>= 1
                right >>= 1
            left = l2
            right = r2

            for i in range(1, self._log + 1):
                if ((left >> i) << i) != left:
                    self._update(left >> i)
                if ((right >> i) << i) != right:
                    self._update((right - 1) >> i)

    def max_right(
            self, left: int, g: typing.Callable[[typing.Any], bool]) -> int:
        assert 0 <= left <= self._n
        assert g(self._e)

        if left == self._n:
            return self._n

        left += self._size
        for i in range(self._log, 0, -1):
            self._push(left >> i)

        sm = self._e
        first = True
        while first or (left & -left) != left:
            first = False
            while left % 2 == 0:
                left >>= 1
            if not g(self._op(sm, self._d[left])):
                while left < self._size:
                    self._push(left)
                    left *= 2
                    if g(self._op(sm, self._d[left])):
                        sm = self._op(sm, self._d[left])
                        left += 1
                return left - self._size
            sm = self._op(sm, self._d[left])
            left += 1

        return self._n

    def min_left(self, right: int, g: typing.Any) -> int:
        assert 0 <= right <= self._n
        assert g(self._e)

        if right == 0:
            return 0

        right += self._size
        for i in range(self._log, 0, -1):
            self._push((right - 1) >> i)

        sm = self._e
        first = True
        while first or (right & -right) != right:
            first = False
            right -= 1
            while right > 1 and right % 2:
                right >>= 1
            if not g(self._op(self._d[right], sm)):
                while right < self._size:
                    self._push(right)
                    right = 2 * right + 1
                    if g(self._op(self._d[right], sm)):
                        sm = self._op(self._d[right], sm)
                        right -= 1
                return right + 1 - self._size
            sm = self._op(self._d[right], sm)

        return 0

    def _update(self, k: int) -> None:
        self._d[k] = self._op(self._d[2 * k], self._d[2 * k + 1])

    def _all_apply(self, k: int, f: typing.Any) -> None:
        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: int) -> None:
        self._all_apply(2 * k, self._lz[k])
        self._all_apply(2 * k + 1, self._lz[k])
        self._lz[k] = self._id

N,Q = list(map(int,input().split()))

D = [1,10]
E = [1,11]
a = 10
mod = 998244353
for i in range(N+1):
    a*=10
    a%=mod
    D.append(a)
    E.append((E[-1]+a)%mod)

def op(a,b):
    return (b[0]+a[0]*D[b[1]])%mod, a[1]+b[1]

e = (0,0)

def mapping(f,a):
    if f is None:
        return a[0],a[1]
    if a[0]==0:
        return 0,0
    return (f*E[a[1]-1])%mod, a[1]

def composition(f,g):
    if f is None:
        return g
    else:
        return f

id = None

lst = LazySegTree(op, e, mapping, composition, id, [(1,1) for i in range(N)])

for i in range(Q):
    l,r,d = list(map(int,input().split()))
    l,r = l-1,r-1
    lst.apply(l,r+1,d)
    print(lst.all_prod()[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())

mozi = list("1"*n)

for i in range(q):
  l,r,d = map(int, input().split())
  
  #print(mozi)
  for j in range(l-1, r):
    #print(mozi[j])
    mozi[j] = str(d)
  
  mozi_hen = "".join(map(str, mozi))
  mozi_hen = int(mozi_hen)
  print(mozi_hen % 998244353)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


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())
S = ["1"] * N
As = []

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

ones = int(str_join(S))
S_tmp = ones
#S_mod = S_int % 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
  tmp = ones * D
  tmp = tmp % left
  tmp = tmp - tmp % right
  S += tmp
  

  #_S = str_join(S)
  print(S % 998_244_353)
  S_tmp = S

Submission status: Time Limit Exceeded

Solution code:
n, q=(int(x) for x in input().split())
s=list(range(n))
for i in range(n):
  s[i]='1'
l=list(range(q))
r=list(range(q))
d=list(range(q))
for i in range(q):
  l[i], r[i], d[i]=(int(x) for x in input().split())
for i in range(q):
  for j in range(l[i]-1,r[i]):
    s[j]=str(d[i])
  print(int(''.join(s))%998244353)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import copy

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    mod=998244353
    n,q=map(int, readline().rstrip().split())
    d = [0]*n

    #memo = [1]*n
    sm = 1
    d[0]=1
    for i in range(1,n):
        d[i]=(d[i-1]*10)%mod
        sm+=d[i]
        sm%=mod
    d1 = copy.copy(d)

    for i in range(q):
        l,r,x=map(int, readline().rstrip().split())
        l-=1
        r-=1
        for j in range(n-1-r,n-l):
            sm -= d[j]
            d[j] = d1[j]*x
            sm += d[j]
            sm %= mod
        print(sm)

    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))

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

ansList = []

for  i in range(q):
    l,r,d = list(map(int,input().split()))
    t = str(d) * (r - l + 1)
    s = s[:l-1] + t + s[r:]
    ansList.append(int(s) % 998244353)

for  i in range(q):
    print(ansList[i])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

S = "1"*N

for i in range(Q):
  L,R,D = input().split()
  L = int(L)
  R = int(R)
  S = S[:L-1] + D*(R-L+1) + S[R:] 
  print(int(S)%998244353)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")
MOD = 998244353


# 処理内容
def main():
    N, Q = map(int, input().split())

    ans = "1" * N
    for _ in range(Q):
        l, r, d = map(int, input().split())
        ans = ans[:l-1] + str(d)*(r-l+1) + ans[r:]
        print(int(ans) % MOD)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())

Q=[]
for i in range(q):
    l,r,d=map(int,input().split())
    Q.append([l,r,d])

ans=['1' for i in range(n)]
for i in range(q):
    ans[Q[i][0]-1:Q[i][1]]=str(Q[i][2])*(Q[i][1]-Q[i][0]+1)
    print(int(''.join(ans))%998244353)

Submission status: Time Limit Exceeded

Solution code:
n, Q = map(int, input().split())
p = 998244353
num_list = [1 for i in range(n)]
def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res
ans = 0
for i in range(n):
    init_ten = power_func(10, i, p)
    ans = (ans + init_ten) % p
for q in range(Q):
    l, r, d = map(int, input().split())
    for i in range(l, r + 1):
        ans = (ans + (d - num_list[i - 1]) * power_func(10, n - i, p)) % p
        num_list[i - 1] = d
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
class LazySegmentTree:
    """
    op: 区間取得クエリでreduceする際に使う演算子
    apply: 更新則の適用
    comp: 更新則の合成
    
    range_query: reduce(op, (apply(x,m) for x,m in zip(X,M)))
    
    満たすべき性質:
    
    集合X (要素)
    op[+]: X,X -> X
    (X, op)はモノイド
    
    集合M (更新則)
    comp[*]: M,M -> M
    (M, compose)はモノイド
    
    apply[f(x,m,n)]: X,M,Z+ -> X
    (Z+は区間長)
    
    f(x,e_M,n) = x
    f(x,m*n,p) = f(f(x,m,p),n,p)
    f(x,m,p)+f(y,m,q) = f(x+y,m,p+q)
    
    参考: https://algo-logic.info/segment-tree/#toc_id_3
    """
    @classmethod
    def all_identity(cls, op, op_e, comp, comp_e, apply, size):
        size = 1 << (size-1).bit_length()
        return cls(
            op,
            op_e,
            comp,
            comp_e,
            apply,
            [op_e]*(2*size),
            [comp_e]*size
        )

    @classmethod
    def from_initial_data(cls, op, op_e, comp, comp_e, apply, data):
        size = 1 << (len(data)-1).bit_length()
        temp = [op_e]*(2*size)
        temp[size:size+len(data)] = data

        for i in reversed(range(size)):
            temp[i] = op(temp[2*i],temp[2*i+1])
        return cls(
            op,
            op_e,
            comp,
            comp_e,
            apply,
            temp,
            [comp_e]*size
        )

    # これ使わずファクトリーメソッド使いましょうね
    def __init__(self, op, op_e, comp, comp_e, apply, data, lazy):
        self.op = op
        self.op_e = op_e
        self.comp = comp
        self.comp_e = comp_e
        self.apply = apply
        self.data = data
        self.lazy = lazy
        self.size = len(self.data)//2
        self.depth = self.size.bit_length()-1
        self._l_indices = [0]*self.depth
        self._r_indices = [0]*self.depth
    
    def _update_indices(self, i, l):
        m = i//(i&-i)
        i >>= 1
        for k in range(self.depth):
            l[k] = i if i < m else 0
            i >>= 1
    
    
    def _propagate_top_down(self):
        data = self.data
        lazy = self.lazy
        apply = self.apply
        comp = self.comp
        comp_e = self.comp_e
        k = self.size >> 1
        
        for i,j in zip(reversed(self._l_indices), reversed(self._r_indices)):
            if i > 0:
                temp = lazy[i]
                if temp != comp_e:
                    lazy[i] = comp_e
                    a = i << 1
                    b = a | 1
                    data[a] = apply(data[a], temp, k)
                    data[b] = apply(data[b], temp, k)
                    if k > 1:
                        lazy[a] = comp(lazy[a], temp)
                        lazy[b] = comp(lazy[b], temp)
            if i < j:
                temp = lazy[j]
                if temp != comp_e:
                    lazy[j] = comp_e
                    a = j << 1
                    b = a | 1
                    data[a] = apply(data[a], temp, k)
                    data[b] = apply(data[b], temp, k)
                    if k > 1:
                        lazy[a] = comp(lazy[a], temp)
                        lazy[b] = comp(lazy[b], temp)
            k >>= 1
            
    def _propagate_bottom_up(self):
        data = self.data
        op = self.op
        for i,j in zip(self._l_indices, self._r_indices):
            if i < j:
                data[j] = op(data[j<<1],data[j<<1|1])
            if i > 0:
                data[i] = op(data[i<<1],data[i<<1|1])
    
    def update_interval(self, l, r, m):
        lazy = self.lazy
        data = self.data
        comp = self.comp
        apply = self.apply
        
        l += self.size
        r += self.size
        self._update_indices(l, self._l_indices)
        self._update_indices(r, self._r_indices)
        self._propagate_top_down()
        k = 1
        while l < r:
            if l & 1:
                data[l] = apply(data[l],m,k)
                if k > 1:
                    lazy[l] = comp(lazy[l],m)
                l += 1
            if r & 1:
                r -= 1
                data[r] = apply(data[r],m,k)
                if k > 1:
                    lazy[r] = comp(lazy[r],m)
            l >>= 1
            r >>= 1
            k <<= 1
        self._propagate_bottom_up()
    
    def get_interval(self, l, r):
        data = self.data
        op = self.op
        
        l += self.size
        r += self.size
        self._update_indices(l, self._l_indices)
        self._update_indices(r, self._r_indices)
        self._propagate_top_down()
        
        lx = self.op_e
        rx = self.op_e
        while l < r:
            if l & 1:
                lx = op(lx, data[l])
                l += 1
            if r & 1:
                r -= 1
                rx = op(data[r], rx)
            l >>= 1
            r >>= 1
        return op(lx,rx)

max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

MOD = 998244353

N,Q = map(int,readline().split())

ones = [0]*N
v = 0
for i in range(N):
    ones[i] = v
    v = (v*10+1)%MOD

power = [0]*N
v = 1
for i in range(N):
    power[i] = v
    v = (v*10)%MOD


# (sum, left_ind)

def compose(x,m):
    return x if m == 0 else m

def apply(x,m,l):
    return x if m == 0 else ((m*ones[l])%MOD, x[1])

def op(a,b):
    x,i = a
    y,j = b
    return (x+y*power[j-i])%MOD, i

seg = LazySegmentTree.from_initial_data(
            op,
            (0,0), 
            compose,
            0,
            apply,
            [(1,i) for i in range(N)])

m = map(int,read().split())

for l,r,d in zip(m,m,m):
    l,r = N-r,N-l
    seg.update_interval(l,r+1,d)
    print(seg.get_interval(0,N)[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#                               #
    # author : samars_diary #
    # 26-09-2020 │ 18:15:45 #
#                               #

import sys, os.path

if(os.path.exists('input.txt')):
    sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def ii(): return int(sys.stdin.readline())
def si(): return sys.stdin.readline().strip()
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a, b = mii() ; a = '1'*a
    for _ in range(b):
        p, q, r = mii()
        r = str(r)*(q-p+1)
        c = a[:p-1] + r + a[q:] 
        a = int(c) % 998244353
        print(a)
        a = str(a)

for _ in range(1): solve()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())

s = '1' * n

mod = 998244353

for _ in range(q):
    l,r,d = input().split()
    l,r = map(lambda x: x-1,map(int,[l,r]))
    s = s[:l] + d * (r-l+1) + s[r+1:]
    
    ans = 0
    for i in range(len(s) // 10):
        ans *= (10 ** 10)
        ans = (ans + int(s[i*10:i*10+10])) % mod
    rem = len(s) % 10
    if(rem):
        ans *= (10 ** rem)
        ans = (ans + int(s[-rem:])) % mod
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = 998244353

def main(N, Q, LRD):
    s = ['1'] * N
    for l, r, d in LRD:
        s[l-1:r] = str(d) * (r-l+1)
        print(int(''.join(s))%mod)


if __name__ == '__main__':
    N, Q = list(map(int, input().split()))
    LRD = [tuple(map(int, input().split())) for q in range(Q)]
    main(N, Q, LRD)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int,input().rstrip().split())
MOD = 998_244_353
s = int("".join(["1"]*n))
for i in range(q):
    l, r, d = map(int,input().rstrip().split())
    a = (s//(10**(n-l+1)))*(10**(n-l+1))
    b = s%(10**(n-r))
    c = int("".join([str(d)]*(r-l+1)))*(10**(n-r))
    s = a+b+c
    print(s%MOD)

Submission status: Time Limit Exceeded

Solution code:
def LI():
    return list(map(int, input().split()))


mod = 998244353

N, Q = LI()
S = "1"*N
ans = int(S) % mod
for _ in range(Q):
    L, R, D = LI()
    D = str(D)
    ans = (ans-int(S[L-1:R])*10**(N-R)) % mod
    d = D*(R-L+1)
    S = S[:L-1]+d+S[R:N]
    d = int(d)
    ans = (ans+d*10**(N-R)) % mod
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import os

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

MOD = 998244353    
N,Q = LI()
LRD = [LI() for _ in range(Q)]
ans = 0

# t = np.ones(N,dtype='int')
t = ['1']*N

for i in range(Q):
    L = LRD[i][0]-1
    R = LRD[i][1]
    D = str(LRD[i][2])
    t[L:R] = [D]*(R-L)
    ans = int(''.join(t)) % 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
    #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
    print(r0)
    s[l:r]=s2
main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def main():
    N, Q = map(int, input().split())
    MOD = 998244353
    S = '1' * N
    for _ in range(Q):
        left, right, n = map(int, input().split())
        left -= 1
        right -= 1
        S = S[:left] + str(n) * (right - left + 1) + S[right + 1:]
        # print(S)
        print(int(S) % MOD)


if __name__ == '__main__':
    main()