Problem p02538 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f ? -x : x;
}
const int N = 2e5 + 1000, mod = 998244353;
int n, m, Pow[N][12], lazy[N << 2], t[N << 2];
void push(int u, int l, int r) {
  if (lazy[u]) {
    int d = lazy[u], mid = l + r >> 1;
    lazy[u << 1 | 1] = lazy[u << 1] = d;
    t[u << 1] = Pow[mid - l + 1][d];
    t[u << 1 | 1] = Pow[r - mid][d];
    lazy[u] = 0;
  }
}
void change(int u, int l, int r, int L, int R, int val) {
  if (r < L || l > R)
    return;
  if (L <= l && r <= R) {
    t[u] = Pow[r - l + 1][val];
    lazy[u] = val;
    return;
  }
  // cout << u <<" "<<l<<" "<<r << endl;
  push(u, l, r);
  int mid = l + r >> 1;
  change(u << 1, l, mid, L, R, val);
  change(u << 1 | 1, mid + 1, r, L, R, val);
  t[u] = (1LL * t[u << 1] * Pow[r - mid][10] % mod + t[u << 1 | 1]) % mod;
}
void build(int u, int l, int r) {
  if (l == r) {
    t[u] = 1;
    return;
  }
  // cout << "now "<< u << " " << endl;
  int mid = l + r >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  t[u] = (1LL * t[u << 1] * Pow[r - mid][10] % mod + t[u << 1 | 1]) % mod;
}
int main() {
  n = read();
  m = read();

  Pow[0][10] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < 10; j++)
      Pow[i][j] = (10LL * Pow[i - 1][j] % mod + j) % mod;
    Pow[i][10] = 10LL * Pow[i - 1][10] % mod;
  }
  build(1, 1, n);
  while (m--) {
    int a = read(), b = read(), c = read();
    // cout << "deg "<< t[1] << endl;
    change(1, 1, n, a, b, c);
    printf("%d\\n", t[1]);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f ? -x : x;
}
struct Node {
  int l, r;
  mutable int v;
  Node(int L, int R = -1, char V = 0) {
    l = L;
    r = R;
    v = V;
  }
  bool operator<(const Node x) const { return l < x.l; }
};
set<Node> s;
const int N = 2e5 + 1000, mod = 998244353;
#define IT set<Node>::iterator
int n, m, Pow[N][11];
IT split(int pos) {
  IT it = s.lower_bound(Node(pos));
  if (it != s.end() && it->l == pos)
    return it;
  it--;
  int l = it->l, r = it->r;
  char v = it->v;
  s.erase(it);
  s.insert(Node(l, pos - 1, v));
  return s.insert(Node(pos, r, v)).first;
}
void assign(int l, int r, int val) {
  IT itr = split(r + 1), itl = split(l);
  s.erase(itl, itr);
  s.insert(Node(l, r, val));
}
int main() {
  n = read();
  m = read();
  s.insert(Node(1, n, 1));
  Pow[0][10] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < 10; j++)
      Pow[i][j] = (10LL * Pow[i - 1][j] % mod + j) % mod;
    Pow[i][10] = 10LL * Pow[i - 1][10] % mod;
  }
  while (m--) {
    int a = read(), b = read(), c = read();
    assign(a, b, c);
    int ans = 0;
    for (IT it = s.begin(); it != s.end(); ++it) {
      int l = it->l, r = it->r, c = it->v;
      // cout << l << " " << r << endl;
      ans = (1LL * ans +
             (Pow[(r - l + 1)][c] * 1LL * Pow[n - r][10] % mod) % mod) %
            mod;
      // cout << Pow[r-l+1][c] << " " <<Pow[n-r][10] << endl;
    }
    printf("%d\\n", ans);
  }
}