Language: C++

#include <bits/stdc++.h>

template <class M, class E, class F = std::function<M(M, M)>, class A = std::function<M(M, E)>, class G = std::function<E(E, E)>>
class LazySegmentTree {
private:
  M* data;
  E* lazy;
  F op;
  G cp;
  A act;
  M e;
  E id;
  int sz;

  void propagate(int index) {
    if (lazy[index] == id) return;
    lazy[index << 1] = cp(lazy[index << 1], lazy[index]);
    lazy[(index << 1) | 1] = cp(lazy[(index << 1) | 1], lazy[index]);
    data[index] = act(data[index], lazy[index]);
    lazy[index] = id;
  }

  void propagate_topdown(int index) {
    int h = 0;
    for (int i = 1; i < index; i <<= 1) ++h;
    for (int i = h; i; i--) propagate(index >> i); 
  }

  void recalc(int index) { while (index >>= 1) data[index] = op(act(data[index << 1], lazy[index << 1]), act(data[(index << 1) | 1], lazy[(index << 1) | 1])); }

public:
  LazySegmentTree(int sz, const F& op, const A& act, const G& cp, const M& e, const E& id) : op(op), act(act), cp(cp), e(e), id(id), sz(sz) {
    data = new M[sz << 1];
    lazy = new E[sz << 1];
    for (int i = 0; i < (sz << 1); i++) data[i] = e;
    for (int i = 0; i < (sz << 1); i++) lazy[i] = id;
  }

  void update(int left, int right, const E& x) {
    if (left < 0) left = 0;
    if (right > sz) right = sz;
    left += sz; right += sz;

    propagate_topdown(left);
    propagate_topdown(right - 1);

    for (int l = left, r = right; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        lazy[l] = cp(lazy[l], x);
        ++l;
      }
      if (r & 1) {
        --r;
        lazy[r] = cp(lazy[r], x);
      }
    }

    recalc(left);
    recalc(right - 1);
  }

  M query(int left, int right) {
    if (left < 0) left = 0;
    if (right > sz) right = sz;
    left += sz; right += sz;

    propagate_topdown(left);
    propagate_topdown(right - 1);

    M l = e, r = e;

    for (; left < right; left >>= 1, right >>= 1) {
      if (left & 1) {
        l = op(l, act(data[left], lazy[left]));
        ++left;
      }
      if (right & 1) {
        --right;
        r = op(act(data[right], lazy[right]), r);
      }
    }

    return op(l, r);
  }

  ~LazySegmentTree() {
    delete[] data;
    delete[] lazy;
  }
  
  void debug() {
    for (int i = sz; i < sz + sz; i++) {
      std::cout << lazy[i].num << ' ' << lazy[i].d << ' ';
    }
    std::cout << std::endl;
  }
};

const int MOD = 998244353;

using namespace std;

struct M {
  long long num;
  long long d;
  M() : num(0), d(0) {}
  M(long long num, long long d) : num(num), d(d) {}
};

bool operator==(const M& a, const M& b) {
  return a.num == b.num && a.d == b.d;
}

struct E {
  int num;
  long long d;
  E() : num(0), d(MOD) {}
  E(int num) : num(num), d(MOD) {}
  E(int num, long long d) : num(num), d(d) {}
};

bool operator==(const E& f, const E& g) {
  return f.num == g.num && f.d == g.d;
}

int main() {
  int N, Q;
  cin >> N >> Q;
  
  auto op = [](const M& a, const M& b) {
    return M((a.num + b.num) % MOD, (a.d + b.d) % MOD);
  };
  
  auto act = [](const M& x, const E& f) {
    if (f.num == 0 && f.d == MOD) return x;
    else if(f.d == MOD) return M(x.d * f.num % MOD, x.d);
    else return M(f.d * f.num % MOD, f.d);
  };
  
  auto cp = [](const E& f, const E& g) {
    if (g.num == 0 && g.d == MOD) return f;
    else if (g.d == MOD) return E(g.num, f.d);
    else return g;
  };
    
  LazySegmentTree<M, E, decltype(op), decltype(act), decltype(cp)> segTree(N, op, act, cp, M(0, 0), E(0, MOD));
  
  segTree.update(N - 1, N, E(1, 1));
  for (int i = N - 1; i > 0; i--) {
    auto s = segTree.query(i, i + 1);
    segTree.update(i - 1, i, E(0, s.d * 10 % MOD));
    segTree.update(i - 1, i, E(1));
  }
  
  while (Q--) {
    int L, R, D;
    cin >> L >> R >> D;
    segTree.update(L - 1, R, D);
    cout << segTree.query(0, N).num << endl;
  }
  
  return 0;
}#include <bits/stdc++.h>

template <class M, class E, class F = std::function<M(M, M)>, class A = std::function<M(M, E)>, class G = std::function<E(E, E)>>
class LazySegmentTree {
private:
  M* data;
  E* lazy;
  F op;
  G cp;
  A act;
  M e;
  E id;
  int sz;

  void propagate(int index) {
    if (lazy[index] == id) return;
    lazy[index << 1] = cp(lazy[index << 1], lazy[index]);
    lazy[(index << 1) | 1] = cp(lazy[(index << 1) | 1], lazy[index]);
    data[index] = act(data[index], lazy[index]);
    lazy[index] = id;
  }

  void propagate_topdown(int index) {
    int h = 0;
    for (int i = 1; i < index; i <<= 1) ++h;
    for (int i = h; i; i--) propagate(index >> i); 
  }

  void recalc(int index) { while (index >>= 1) data[index] = op(act(data[index << 1], lazy[index << 1]), act(data[(index << 1) | 1], lazy[(index << 1) | 1])); }

public:
  LazySegmentTree(int sz, const F& op, const A& act, const G& cp, const M& e, const E& id) : op(op), act(act), cp(cp), e(e), id(id), sz(sz) {
    data = new M[sz << 1];
    lazy = new E[sz << 1];
    for (int i = 0; i < (sz << 1); i++) data[i] = e;
    for (int i = 0; i < (sz << 1); i++) lazy[i] = id;
  }

  void update(int left, int right, const E& x) {
    if (left < 0) left = 0;
    if (right > sz) right = sz;
    left += sz; right += sz;

    propagate_topdown(left);
    propagate_topdown(right - 1);

    for (int l = left, r = right; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        lazy[l] = cp(lazy[l], x);
        ++l;
      }
      if (r & 1) {
        --r;
        lazy[r] = cp(lazy[r], x);
      }
    }

    recalc(left);
    recalc(right - 1);
  }

  M query(int left, int right) {
    if (left < 0) left = 0;
    if (right > sz) right = sz;
    left += sz; right += sz;

    propagate_topdown(left);
    propagate_topdown(right - 1);

    M l = e, r = e;

    for (; left < right; left >>= 1, right >>= 1) {
      if (left & 1) {
        l = op(l, act(data[left], lazy[left]));
        ++left;
      }
      if (right & 1) {
        --right;
        r = op(act(data[right], lazy[right]), r);
      }
    }

    return op(l, r);
  }

  ~LazySegmentTree() {
    delete[] data;
    delete[] lazy;
  }
  
  void debug() {
    for (int i = sz; i < sz + sz; i++) {
      std::cout << lazy[i].num << ' ' << lazy[i].d << ' ';
    }
    std::cout << std::endl;
  }
};

const int MOD = 998244353;

using namespace std;

struct M {
  long long num;
  long long d;
  M() : num(0), d(0) {}
  M(long long num, long long d) : num(num), d(d) {}
};

bool operator==(const M& a, const M& b) {
  return a.num == b.num && a.d == b.d;
}

struct E {
  int num;
  long long d;
  E() : num(0), d(MOD) {}
  E(int num) : num(num), d(MOD) {}
  E(int num, long long d) : num(num), d(d) {}
};

bool operator==(const E& f, const E& g) {
  return f.num == g.num && f.d == g.d;
}

int main() {
  int N, Q;
  cin >> N >> Q;
  
  auto op = [](const M& a, const M& b) {
    return M((a.num + b.num) % MOD, (a.d + b.d) % MOD);
  };
  
  auto act = [](const M& x, const E& f) {
    if (f.num == 0 && f.d == MOD) return x;
    else if(f.d == MOD) return M(x.d * f.num % MOD, x.d);
    else return M(f.d * f.num % MOD, f.d);
  };
  
  auto cp = [](const E& f, const E& g) {
    if (g.num == 0 && g.d == MOD) return f;
    else if (g.d == MOD) return E(g.num, f.d);
    else return g;
  };
    
  LazySegmentTree<M, E, decltype(op), decltype(act), decltype(cp)> segTree(N, op, act, cp, M(0, 0), E(0, MOD));
  
  segTree.update(N - 1, N, E(1, 1));
  for (int i = N - 1; i > 0; i--) {
    auto s = segTree.query(i, i + 1);
    segTree.update(i - 1, i, E(0, s.d * 10 % MOD));
    segTree.update(i - 1, i, E(1));
  }
  
  while (Q--) {
    int L, R, D;
    cin >> L >> R >> D;
    segTree.update(L - 1, R, D);
    cout << segTree.query(0, N).num << endl;
  }
  
  return 0;
}

Compiler output:
a.cc:163:2: error: stray '#' in program
  163 | }#include <bits/stdc++.h>
      |  ^
a.cc:163:3: error: 'include' does not name a type
  163 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:261:11: error: redefinition of 'const int MOD'
  261 | const int MOD = 998244353;
      |           ^~~
a.cc:99:11: note: 'const int MOD' previously defined here
   99 | const int MOD = 998244353;
      |           ^~~
a.cc:265:8: error: redefinition of 'struct M'
  265 | struct M {
      |        ^
a.cc:103:8: note: previous definition of 'struct M'
  103 | struct M {
      |        ^
a.cc:272:6: error: redefinition of 'bool operator==(const M&, const M&)'
  272 | bool operator==(const M& a, const M& b) {
      |      ^~~~~~~~
a.cc:110:6: note: 'bool operator==(const M&, const M&)' previously defined here
  110 | bool operator==(const M& a, const M& b) {
      |      ^~~~~~~~
a.cc:276:8: error: redefinition of 'struct E'
  276 | struct E {
      |        ^
a.cc:114:8: note: previous definition of 'struct E'
  114 | struct E {
      |        ^
a.cc:284:6: error: redefinition of 'bool operator==(const E&, const E&)'
  284 | bool operator==(const E& f, const E& g) {
      |      ^~~~~~~~
a.cc:122:6: note: 'bool operator==(const E&, const E&)' previously defined here
  122 | bool operator==(const E& f, const E& g) {
      |      ^~~~~~~~
a.cc:288:5: error: redefinition of 'int main()'
  288 | int main() {
      |     ^~~~
a.cc:126:5: note: 'int main()' previously defined here
  126 | int main() {
      |     ^~~~
a.cc: In constructor 'LazySegmentTree<M, E, F, A, G>::LazySegmentTree(int, const F&, const A&, const G&, const M&, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:32:3: error: mangling of 'LazySegmentTree<M, E, F, A, G>::LazySegmentTree(int, const F&, const A&, const G&, const M&, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_EC2EiRKS4_RKS7_RKS8_S3_S6_' conflicts with a previous mangle
   32 |   LazySegmentTree(int sz, const F& op, const A& act, const G& cp, const M& e, const E& id) : op(op), act(act), cp(cp), e(e), id(id), sz(sz) {
      |   ^~~~~~~~~~~~~~~
a.cc:32:3: note: previous mangling 'LazySegmentTree<M, E, F, A, G>::LazySegmentTree(int, const F&, const A&, const G&, const M&, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:32:3: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In member function 'void LazySegmentTree<M, E, F, A, G>::update(int, int, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:39:8: error: mangling of 'void LazySegmentTree<M, E, F, A, G>::update(int, int, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_E6updateEiiS6_' conflicts with a previous mangle
   39 |   void update(int left, int right, const E& x) {
      |        ^~~~~~
a.cc:39:8: note: previous mangling 'void LazySegmentTree<M, E, F, A, G>::update(int, int, const E&) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:39:8: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In member function 'void LazySegmentTree<M, E, F, A, G>::propagate_topdown(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:23:8: error: mangling of 'void LazySegmentTree<M, E, F, A, G>::propagate_topdown(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_E17propagate_topdownEi' conflicts with a previous mangle
   23 |   void propagate_topdown(int index) {
      |        ^~~~~~~~~~~~~~~~~
a.cc:23:8: note: previous mangling 'void LazySegmentTree<M, E, F, A, G>::propagate_topdown(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:23:8: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In member function 'void LazySegmentTree<M, E, F, A, G>::propagate(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:15:8: error: mangling of 'void LazySegmentTree<M, E, F, A, G>::propagate(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_E9propagateEi' conflicts with a previous mangle
   15 |   void propagate(int index) {
      |        ^~~~~~~~~
a.cc:15:8: note: previous mangling 'void LazySegmentTree<M, E, F, A, G>::propagate(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:15:8: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In lambda function:
a.cc:296:14: error: mangling of 'main()::<lambda(const M&, const E&)>' as '_ZZ4mainENKUlRK1MRK1EE_clES1_S4_' conflicts with a previous mangle
  296 |   auto act = [](const M& x, const E& f) {
      |              ^
a.cc:134:14: note: previous mangling 'main()::<lambda(const M&, const E&)>'
  134 |   auto act = [](const M& x, const E& f) {
      |              ^
a.cc:296:14: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
  296 |   auto act = [](const M& x, const E& f) {
      |              ^
a.cc: In lambda function:
a.cc:302:13: error: mangling of 'main()::<lambda(const E&, const E&)>' as '_ZZ4mainENKUlRK1ES1_E_clES1_S1_' conflicts with a previous mangle
  302 |   auto cp = [](const E& f, const E& g) {
      |             ^
a.cc:140:13: note: previous mangling 'main()::<lambda(const E&, const E&)>'
  140 |   auto cp = [](const E& f, const E& g) {
      |             ^
a.cc:302:13: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
  302 |   auto cp = [](const E& f, const E& g) {
      |             ^
a.cc: In member function 'void LazySegmentTree<M, E, F, A, G>::recalc(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:29:8: error: mangling of 'void LazySegmentTree<M, E, F, A, G>::recalc(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_E6recalcEi' conflicts with a previous mangle
   29 |   void recalc(int index) { while (index >>= 1) data[index] = op(act(data[index << 1], lazy[index << 1]), act(data[(index << 1) | 1], lazy[(index << 1) | 1])); }
      |        ^~~~~~
a.cc:29:8: note: previous mangling 'void LazySegmentTree<M, E, F, A, G>::recalc(int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:29:8: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In member function 'M LazySegmentTree<M, E, F, A, G>::query(int, int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:62:5: error: mangling of 'M LazySegmentTree<M, E, F, A, G>::query(int, int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_E5queryEii' conflicts with a previous mangle
   62 |   M query(int left, int right) {
      |     ^~~~~
a.cc:62:5: note: previous mangling 'M LazySegmentTree<M, E, F, A, G>::query(int, int) [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:62:5: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling
a.cc: In destructor 'LazySegmentTree<M, E, F, A, G>::~LazySegmentTree() [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]':
a.cc:86:3: error: mangling of 'LazySegmentTree<M, E, F, A, G>::~LazySegmentTree() [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]' as '_ZN15LazySegmentTreeI1M1EZ4mainEUlRKS0_S3_E_Z4mainEUlS3_RKS1_E_Z4mainEUlS6_S6_E_ED2Ev' conflicts with a previous mangle
   86 |   ~LazySegmentTree() {
      |   ^
a.cc:86:3: note: previous mangling 'LazySegmentTree<M, E, F, A, G>::~LazySegmentTree() [with M = M; E = E; F = main()::<lambda(const M&, const M&)>; A = main()::<lambda(const M&, const E&)>; G = main()::<lambda(const E&, const E&)>]'
a.cc:86:3: note: a later '-fabi-version=' (or =0) avoids this error with a change in mangling