Problem p02538 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e6 + 3;
const int mod = 998244353;
ll n, q, l, r, k;
ll num[N], all_1[N];
struct A {
  ll l, r, num, lazy;
} a[N];
void f(int root, int k) {
  a[root].lazy = k;
  a[root].num = (k * all_1[a[root].r - a[root].l + 1]) % mod;
}
void pushback(int root) {
  int l = a[root].l;
  int r = a[root].r;
  ll mid = (l + r) >> 1;
  if (a[root].lazy != 0) {
    f(root << 1, a[root].lazy);
    f(root << 1 | 1, a[root].lazy);
  }
  a[root].lazy = 0;
}
void pushup(int root) {
  a[root].num = (a[root << 1].num * num[a[root << 1 | 1].r - a[root << 1].r] +
                 a[root << 1 | 1].num) %
                mod;
}
void buid(int l, int r, int root) {
  a[root].l = l;
  a[root].r = r;
  if (l == r) {
    a[root].num = 1;
    return;
  }
  ll mid = (l + r) >> 1;
  buid(l, mid, root << 1);
  buid(mid + 1, r, root << 1 | 1);
  pushup(root);
}
void update(ll l, ll r, ll root, ll d) {
  pushback(root);
  if (a[root].r <= r && a[root].l >= l) {
    f(root, d);
    return;
  }
  ll mid = (a[root].l + a[root].r) >> 1;
  if (mid >= l) {
    update(l, r, root << 1, d);
  }
  if (mid < r) {
    update(l, r, root << 1 | 1, d);
  }
  pushup(root);
}
ll quary(ll l, ll r, ll root) {
  pushback(root);
  if (a[root].l >= l && a[root].r <= r) {
    return a[root].num;
  }
  int mid = (a[root].r + a[root].l) / 2;
  ll lso = 0, rso = 0;
  if (mid >= l) {
    lso = quary(l, r, root << 1);
  }
  if (mid < r) {
    rso = quary(l, r, root << 1 | 1);
  }
  ll sum = (lso * (n - a[root << 1].r) + rso) % mod;
  return sum;
}
int main() {
  cin >> n >> q;
  num[0] = 1;
  for (int i = 1; i <= n; i++)
    num[i] = (num[i - 1] * 10) % mod;
  all_1[1] = 1;
  for (int i = 2; i <= n; i++)
    all_1[i] = (all_1[i - 1] * 10 + 1) % mod;
  buid(1, n, 1);
  while (q--) {
    cin >> l >> r >> k;
    update(l, r, 1, k);
    cout << quary(1, n, 1) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 3;
const int mod = 998244353;
ll n, q, l, r, k;
ll num[N], all_1[N];
struct A {
  ll l, r, num, lazy;
} a[N];
void f(int root, int k) {
  a[root].lazy = k;
  a[root].num = (k * all_1[a[root].r - a[root].l + 1]) % mod;
}
void pushback(int root) {
  int l = a[root].l;
  int r = a[root].r;
  ll mid = (l + r) >> 1;
  if (a[root].lazy != 0) {
    f(root << 1, a[root].lazy);
    f(root << 1 | 1, a[root].lazy);
  }
  a[root].lazy = 0;
}
void pushup(int root) {
  a[root].num = (a[root << 1].num * num[a[root << 1 | 1].r - a[root << 1].r] +
                 a[root << 1 | 1].num) %
                mod;
}
void buid(int l, int r, int root) {
  a[root].l = l;
  a[root].r = r;
  if (l == r) {
    a[root].num = 1;
    return;
  }
  ll mid = (l + r) >> 1;
  buid(l, mid, root << 1);
  buid(mid + 1, r, root << 1 | 1);
  pushup(root);
}
void update(ll l, ll r, ll root, ll d) {
  pushback(root);
  if (a[root].r <= r && a[root].l >= l) {
    f(root, d);
    return;
  }
  ll mid = (a[root].l + a[root].r) >> 1;
  if (mid >= l) {
    update(l, r, root << 1, d);
  }
  if (mid < r) {
    update(l, r, root << 1 | 1, d);
  }
  pushup(root);
}
ll quary(ll l, ll r, ll root) {
  pushback(root);
  if (a[root].l >= l && a[root].r <= r) {
    return a[root].num;
  }
  int mid = (a[root].r + a[root].l) / 2;
  ll lso = 0, rso = 0;
  if (mid >= l) {
    lso = quary(l, r, root << 1);
  }
  if (mid < r) {
    rso = quary(l, r, root << 1 | 1);
  }
  ll sum = (lso * (n - a[root << 1].r) + rso) % mod;
  return sum;
}
int main() {
  cin >> n >> q;
  num[0] = 1;
  for (int i = 1; i <= n; i++)
    num[i] = (num[i - 1] * 10) % mod;
  all_1[1] = 1;
  for (int i = 2; i <= n; i++)
    all_1[i] = (all_1[i - 1] * 10 + 1) % mod;
  buid(1, n, 1);
  while (q--) {
    cin >> l >> r >> k;
    update(l, r, 1, k);
    cout << quary(1, n, 1) << endl;
  }
  return 0;
}