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 Julia (1.4.0) (judge verdict: Time Limit Exceeded)

#const A_MAX=300_001
#const INV=-1
const MOD=998_244_353

mutable struct Elem
    s::Int
    l::Int
end

const INV=Elem(-1,-1)

function comp(e1::Elem,e2::Elem)::Elem
    s=e1.s
    s*=D[e2.l+1]
    s%=MOD
    #for i=1:e2.l
    #    s*=10
    #    s%=MOD
    #end
    #s*=(10^e2.l)%MOD
    s%=MOD
    s+=e2.s
    s%=MOD
    return Elem(s,e1.l+e2.l)
end

mutable struct SegmentTree
    data::Array{Elem}
    lazy::Array{Elem}
    ndata::Int

end

function init(st::SegmentTree,n::Int)
    x=1::Int
    while n > x
        x *=2
    end

    st.data=fill(INV,2x) #Array{Elem}(2x)
    for i=1:x
        if i<=n
            st.data[x-1+i]=Elem(1,1)
        else
            st.data[x-1+i]=Elem(0,0)
        end
    end
    for i=1:x-1
        k=x-i
        st.data[k]=comp(st.data[2k],st.data[2k+1])
    end
    #st.data=ones(Int,2x)
    st.lazy=fill(INV, 2x)
    st.ndata=x
end

function eval(st::SegmentTree, k::Int)
    if st.lazy[k] == INV
        return
    end
    s=st.lazy[k].s
    l=st.lazy[k].l
    if k < st.ndata
        st.lazy[2k]=Elem(s,div(l,2))#st.lazy[k]
        st.lazy[2k+1]=Elem(s,div(l,2))#st.lazy[k]
    end
    st.data[k]= rgval(0,l,s) #st.lazy[k] #####
    st.lazy[k]=INV
end

function rgval(r::Int,l::Int,x::Int)::Elem
    d=l-r
    _x=x
    s=x
    for i=1:d-1
        _x*=10
        _x%=MOD
        s+=_x
        s%=MOD
    end
    return Elem(s,d)

end

function update(st::SegmentTree, i::Int, x::Int)
    idx = i+st.ndata-1
    st.data[idx] = Elem(x,1)
    while idx > 1
        idx = div(idx, 2)
        st.data[idx] = comp(st.data[2idx],st.data[2idx+1])
    end
end
function update(st::SegmentTree, a::Int,b::Int,x::Int)
    update(st,a,b,x,1,1,st.ndata+1)
end
function update(st::SegmentTree,a::Int,b::Int,x::Int,k::Int,l::Int,r::Int)
    #println(" update($a,$b,$x,$k,$l,$r)")
    eval(st,k)
    if a <= l && r <= b
        st.lazy[k] = Elem(x,r-l) #rgval(l,r,x)
        eval(st,k)
    elseif a < r && l < b
        update(st,a,b,x,2k,l,div(l+r,2))
        update(st,a,b,x,2k+1,div(l+r,2),r)
        st.data[k]=comp(st.data[2k],st.data[2k+1])
    end
end
function query(st::SegmentTree, i::Int)
    return query(st,i,i+1)
end

function query(st::SegmentTree,a::Int, b::Int)
    return query_sub(st, a,b,1,1,st.ndata+1)
end

function query_sub(st::SegmentTree, a::Int,b::Int, k::Int, l::Int, r::Int)
    eval(st,k)
    if r <=a || b <= l
        return Elem(0,0)
    elseif a <= l && r <= b
        return st.data[k]
    else
        vl = query_sub(st, a,b,2k,l,div(l+r,2))
        vr = query_sub(st, a,b,2k+1,div(l+r,2),r)
        return comp(vl, vr)
    end
end



function solve()
    N,Q=parse.(Int, split(readline()))
    t=1
    for i=1:N+1
        global D[i]=t
        t*=10
        t%=MOD
    end

    st=SegmentTree([],[],0)
    init(st,N)
    for i =1:Q
        Li,Ri,Qi=parse.(Int,split(readline()))
        update(st,Li,Ri+1,Qi)
        e=query(st,1,N+1)
        #println(st)
        println(e.s)
    end
    #println(query(st,1,N+1))

end

D=zeros(Int,200001)

solve()