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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#define N1 200005
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
using namespace std;

int n, Q;
ll val[10][N1], m10[N1];

struct SEG {
  ll sum[N1 << 2];
  int tag[N1 << 2];
  void pushup(int len, int rt) {
    sum[rt] = (sum[rt << 1] * m10[len] % mod + sum[rt << 1 | 1]) % mod;
  }
  void pushdown(int l, int r, int mid, int rt) {
    if (!tag[rt])
      return;
    int w = tag[rt];
    sum[rt << 1] = val[w][mid - l + 1];
    tag[rt << 1] = w;
    sum[rt << 1 | 1] = val[w][r - mid];
    tag[rt << 1 | 1] = w;
    tag[rt] = 0;
  }
  void upd(int L, int R, int l, int r, int rt, int w) {
    if (L <= l && r <= R) {
      sum[rt] = val[w][r - l + 1];
      tag[rt] = w;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(l, r, mid, rt);
    if (L <= mid)
      upd(L, R, l, mid, rt << 1, w);
    if (R > mid)
      upd(L, R, mid + 1, r, rt << 1 | 1, w);
    pushup(r - mid, rt);
  }
  /*ll query(int L,int R,int l,int r,int rt)
  {
          if(L<=l&&r<=R) return sum[rt];
          int mid=(l+r)>>1; ll ans=0;
          if(L<=mid) ans=query(L,R,l,mid,rt<<1)*m10[r-mid]%mod;
          if(R>mid) ans=ans+query(L,R,mid+1,r,rt<<1|1);
          pushup(mid-l+1,rt);
          return ans%mod;
  }*/
} s;

void pro() {
  m10[0] = 1;
  for (int i = 1; i <= n; i++)
    m10[i] = m10[i - 1] * 10 % mod;
  for (int j = 1; j <= 9; j++) {
    val[j][0] = 0;
    for (int i = 1; i <= n; i++) {
      val[j][i] = (val[j][i - 1] * 10 % mod + j) % mod;
    }
  }
  s.upd(1, n, 1, n, 1, 1);
}

int main() {
  //	freopen("e.txt","r",stdin);
  scanf("%d%d", &n, &Q);
  pro();
  int l, r, w;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d%d", &l, &r, &w);
    s.upd(l, r, 1, n, 1, w);
    printf("%lld\\n", s.sum[1]);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#define N1 200005
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
using namespace std;

int n, Q;
ll val[10][N1], m10[N1];

struct SEG {
  ll sum[N1 << 2];
  int tag[N1];
  void pushup(int len, int rt) {
    sum[rt] = (sum[rt << 1] * m10[len] % mod + sum[rt << 1 | 1]) % mod;
  }
  void pushdown(int l, int r, int mid, int rt) {
    if (!tag[rt])
      return;
    int w = tag[rt];
    sum[rt << 1] = val[w][mid - l + 1];
    tag[rt << 1] = w;
    sum[rt << 1 | 1] = val[w][r - mid];
    tag[rt << 1 | 1] = w;
    tag[rt] = 0;
  }
  void upd(int L, int R, int l, int r, int rt, int w) {
    if (L <= l && r <= R) {
      sum[rt] = val[w][r - l + 1];
      tag[rt] = w;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(l, r, mid, rt);
    if (L <= mid)
      upd(L, R, l, mid, rt << 1, w);
    if (R > mid)
      upd(L, R, mid + 1, r, rt << 1 | 1, w);
    pushup(r - mid, rt);
  }
  /*ll query(int L,int R,int l,int r,int rt)
  {
          if(L<=l&&r<=R) return sum[rt];
          int mid=(l+r)>>1; ll ans=0;
          if(L<=mid) ans=query(L,R,l,mid,rt<<1)*m10[r-mid]%mod;
          if(R>mid) ans=ans+query(L,R,mid+1,r,rt<<1|1);
          pushup(mid-l+1,rt);
          return ans%mod;
  }*/
} s;

void pro() {
  m10[0] = 1;
  for (int i = 1; i <= n; i++)
    m10[i] = m10[i - 1] * 10 % mod;
  for (int j = 1; j <= 9; j++) {
    val[j][0] = 0;
    for (int i = 1; i <= n; i++) {
      val[j][i] = (val[j][i - 1] * 10 % mod + j) % mod;
    }
  }
  s.upd(1, n, 1, n, 1, 1);
}

int main() {
  //	freopen("e.txt","r",stdin);
  scanf("%d%d", &n, &Q);
  pro();
  int l, r, w;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d%d", &l, &r, &w);
    s.upd(l, r, 1, n, 1, w);
    printf("%lld\\n", s.sum[1]);
  }
  return 0;
}