alexjercan/bugnet huggingface dataset:
Problem p02471 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll s1, s2, s, t1, t2, t;

void xgcd(ll x, ll y) {
  if (x % y == 0)
    return;
  ll q = x / y;
  s = s2 - q * s1;
  t = t2 - q * t1;
  s2 = s1, t2 = t1, s1 = s, t1 = t;
  xgcd(y, x % y);
}

int main() {
  ll a, b;
  // while(1) {
  cin >> a >> b;
  s1 = 0;
  s2 = 1;
  t1 = 1;
  t2 = 0;
  xgcd(a, b);
  cout << s1 << " " << t1 << endl;
  //}
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll s1, s2, s, t1, t2, t;

void xgcd(ll x, ll y) {
  if (x % y == 0)
    return;
  ll q = x / y;
  s = s2 - q * s1;
  t = t2 - q * t1;
  s2 = s1, t2 = t1, s1 = s, t1 = t;
  xgcd(y, x % y);
}

int main() {
  ll a, b;
  while (1) {
    cin >> a >> b;
    s1 = 0;
    s2 = 1;
    t1 = 1;
    t2 = 0;
    xgcd(a, b);
    cout << s1 << " " << t1 << endl;
  }
  return 0;
}
Problem p02534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K;
  cin >> K;

  int i = 0;
  while (i < K) {
    cout << "ACL";
    i++;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K;
  int i = 0;
  cin >> K;

  while (K <= 5) {
    cout << "ACL" << endl;
    i++;
  }
}
Problem p02534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string ans, p = "ACL";
  while (t > 0) {

    ans += p;
    t--;
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string p = "ACL", ans = "";
  while (t > 0) {
    ans += p;
  }
  cout << ans;

  return 0;
}
Problem p02534 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int k = 0;
  cin >> k;
  string a = "ACL";
  string c = a + a;
  for (int i = 0; i < k; i++) {
    c = c + a;
    cout << a;
  }

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k = 0;
  cin >> k;
  char a[] = "ACL";
  char b[] = "ACL";
  for (int i = 0; i < k; i++)
    strcat(a, b);
  cout << a;
  return 0;
}
Problem p02534 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  while (n--) {
    cout << "ACL";
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n;
  while (n--) {
    cout << "ACL";
  }
}
Problem p02538 (C++) — buggy submission, verdict: Runtime Error

// #define _GLIBCXX_DEBUG
#include <atcoder/lazysegtree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using ll = int64_t;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()

ll le = 200010;
vector<vector<ll>> M(le, vector<ll>(10, 0));
vector<ll> MODS(le, 0);
ll mod = 998244353;

struct S {
  ll v, size;
};

S op(S a, S b) {
  // cout << "MODS " << b.size << " " << MODS[b.size] << '\\n';
  return {(MODS[b.size] * a.v + b.v) % mod, a.size + b.size};
}

S e() { return {0, 0}; }

S mapping(ll f, S x) {
  // cout << M[x.size][f] << '\\n';
  if (f != 0) {
    return {M[x.size][f], x.size};
  } else {
    return x;
  }
}

ll composition(ll f, ll g) {
  if (f != 0) {
    return f;
  } else {
    return g;
  }
}

ll id() { return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, q, l, r, d;
  cin >> n >> q;
  vector<S> A;
  rep(i, n) { A.push_back(S{1, 1}); }

  rep(i, 10) { M[1][i] = i; }
  rep(i, 10) {
    for (int j = 2; j < le; j++) {
      M[j][i] = (M[j - 1][i] * 10) % mod;
    }
    for (int j = 2; j < le; j++) {
      M[j][i] = (M[j][i] + M[j - 1][i]) % mod;
    }
  }
  MODS[0] = 1;
  for (int j = 1; j < le; j++) {
    MODS[j] = (MODS[j - 1] * 10) % mod;
  }

  lazy_segtree<S, op, e, ll, mapping, composition, id> seg(A);

  // cout << seg.all_prod().v << '\\n';
  rep(i, q) {
    cin >> l >> r >> d;
    seg.apply(l - 1, r, d);
    cout << seg.all_prod().v << '\\n';
  }
}

// 「#define _GLIBCXX_DEBUG」をコメントアウトしましたか？？

Error: WA

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, q, mod, ans;
  ans = 0;
  cin >> n >> q;
  vector<vector<int64_t>> C(q + 1, vector<int64_t>(3));
  C[0][0] = 1;
  C[0][1] = n;
  C[0][2] = 1;
  rep(i, q) { cin >> C[i + 1][0] >> C[i + 1][1] >> C[i + 1][2]; }
  q++;
  rep(i, q) {
    rep(j, 2) { C[i][j] -= 1; }
  }

  mod = 998244353;
  vector<int64_t> M10;
  int64_t mm = 1;
  rep(i, n) {
    M10.push_back(mm);
    mm = (mm * 10) % mod;
  }
  // cout << "OK";
  set<int64_t> S;
  rep(i, n) { S.insert(i); }
  int mi = n;
  for (int i = q - 1; i >= 0; i--) {
    // auto fs = S.upper_bound(C[i][1]);
    // cout << "i=" << i << endl;
    if (mi > 0) {
      for (auto fi = S.lower_bound(C[i][0]);;) {
        // cout << *fi << endl;
        mi--;
        ans = (ans + C[i][2] * M10[n - 1 - (*fi)]) % mod;
        if (mi == 0) {
          break;
        }
        fi = S.erase(fi);
        if (fi == S.end() || *fi >= C[i][1] + 1) {
          break;
        }
      }
    }
  }

  cout << ans << endl;
}
Problem p02538 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353;
const int MAXN = 400010;
using ll = long long;
ll po10[MAXN], popsum[MAXN];

using PII = pair<int, int>;
using PIII = pair<PII, int>;
set<PIII> st;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  po10[0] = 0;
  po10[1] = 1;
  for (int i = 2; i <= n; i++) {
    po10[i] = po10[i - 1] * 10 % mod;
  }
  popsum[0] = 0;
  for (int i = 1; i <= n; i++) {
    popsum[i] = (popsum[i - 1] + po10[i]) % mod;
  }
  ll ans = popsum[n];
  st.insert({{1, n}, 1});
  queue<PIII> q;
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    l = n + 1 - l;
    r = n + 1 - r;
    swap(l, r);
    PIII p{{l, r}, x};
    auto it = st.upper_bound(p);
    if (it == st.end() || it->first.first > l) {
      --it;
    }
    int xb = it->second;
    int lb = it->first.first;
    int rb = it->first.second;
    while (lb <= r) {
      // printf("%d %d %d\\n",lb,rb,xb);
      int low = max(l, lb);
      int high = min(r, rb);
      ans += (popsum[high] - popsum[low - 1] + mod) % mod * ((ll)x - xb + mod) %
             mod;
      ans %= mod;
      it = st.erase(it);
      if (lb <= l - 1)
        q.push({{lb, l - 1}, xb});
      if (r + 1 <= rb)
        q.push({{r + 1, rb}, xb});
      if (it == st.end())
        break;
      xb = it->second;
      lb = it->first.first;
      rb = it->first.second;
    }
    while (!q.empty()) {
      st.insert(q.front());
      q.pop();
    }
    st.insert(p);
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353;
const int MAXN = 200010;
using ll = long long;
ll po10[MAXN], popsum[MAXN];

using PII = pair<int, int>;
using PIII = pair<PII, int>;
set<PIII> st;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  po10[0] = 0;
  po10[1] = 1;
  for (int i = 2; i <= n; i++) {
    po10[i] = po10[i - 1] * 10 % mod;
  }
  popsum[0] = 0;
  for (int i = 1; i <= n; i++) {
    popsum[i] = (popsum[i - 1] + po10[i]) % mod;
  }
  ll ans = popsum[n];
  st.insert({{1, n}, 1});
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    l = n + 1 - l;
    r = n + 1 - r;
    swap(l, r);
    PIII p{{l, r}, x};
    auto it = st.upper_bound(p);
    --it;
    int xb = it->second;
    int lb = it->first.first;
    int rb = it->first.second;
    queue<PIII> q;
    while (lb <= r) {
      // printf("%d %d %d\\n",lb,rb,xb);
      int low = max(l, lb);
      int high = min(r, rb);
      ans += (popsum[high] - popsum[low - 1] + mod) % mod * ((ll)x - xb + mod) %
             mod;
      ans %= mod;
      it = st.erase(it);
      if (lb <= l - 1)
        q.push({{lb, l - 1}, xb});
      if (r + 1 <= rb)
        q.push({{r + 1, rb}, xb});
      if (it == st.end())
        break;
      xb = it->second;
      lb = it->first.first;
      rb = it->first.second;
    }
    while (!q.empty()) {
      st.insert(q.front());
      q.pop();
    }
    st.insert(p);
    printf("%lld\\n", ans);
  }
  return 0;
}
Problem p02538 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rp1(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define rp0(i, n) for ((i) = 0; (i) < (n); (i)++)
using namespace std;
const int mod = 998244353;
int n, q, f[800005], tag[800005], s[800005], lst = 1;
void build(int x, int l, int r) {
  tag[x] = 0;
  if (l == r) {
    f[x] = s[x] = lst;
    lst = 10ll * lst % mod;
    return;
  }
  int mid = (l + r) / 2;
  build(x + x + 1, mid + 1, r);
  build(x + x, l, mid);
  s[x] = f[x] = (f[x + x] + f[x + x + 1]) % mod;
}
void update(int x, int l, int r, int ll, int rr, int c) {
  if (ll <= l && r <= rr) {
    tag[x] = c;
    s[x] = 1ll * f[x] * c % mod;
    return;
  }
  if (tag[x]) {
    tag[x + x] = tag[x + x + 1] = tag[x];
    s[x + x] = 1ll * f[x + x] * tag[x] % mod;
    s[x + x + 1] = 1ll * f[x + x + 1] * tag[x] % mod;
    tag[x] = 0;
  }
  int mid = (l + r) / 2;
  if (ll <= mid)
    update(x + x, l, mid, ll, rr, c);
  if (rr > mid)
    update(x + x + 1, mid + 1, r, ll, rr, c);
  s[x] = (s[x + x] + s[x + x + 1]) % mod;
}
int main() {
  cin >> n >> q;
  int i;
  build(1, 1, n);
  rp0(i, q) {
    int l, r, d;
    cin >> l >> r >> d;
    update(1, 1, n, l, r, d);
    cout << s[1] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rp1(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define rp0(i, n) for ((i) = 0; (i) < (n); (i)++)
using namespace std;
const int mod = 998244353;
int n, q, f[800005], tag[800005], s[800005], lst = 1;
void build(int x, int l, int r) {
  tag[x] = 0;
  if (l == r) {
    f[x] = s[x] = lst;
    lst = 10ll * lst % mod;
    return;
  }
  int mid = (l + r) / 2;
  build(x + x + 1, mid + 1, r);
  build(x + x, l, mid);
  s[x] = f[x] = (f[x + x] + f[x + x + 1]) % mod;
}
void update(int x, int l, int r, int ll, int rr, int c) {
  if (l == r) {
    tag[x] = c;
    s[x] = 1ll * f[x] * c % mod;
    return;
  }
  if (tag[x]) {
    tag[x + x] = tag[x + x + 1] = tag[x];
    s[x + x] = 1ll * f[x + x] * tag[x] % mod;
    s[x + x + 1] = 1ll * f[x + x + 1] * tag[x] % mod;
    tag[x] = 0;
  }
  int mid = (l + r) / 2;
  if (ll <= mid)
    update(x + x, l, mid, ll, rr, c);
  if (rr > mid)
    update(x + x + 1, mid + 1, r, ll, rr, c);
  s[x] = (s[x + x] + s[x + x + 1]) % mod;
}
int main() {
  cin >> n >> q;
  int i;
  build(1, 1, n);
  rp0(i, q) {
    int l, r, d;
    cin >> l >> r >> d;
    update(1, 1, n, l, r, d);
    cout << s[1] << endl;
  }
  return 0;
}
Problem p02538 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int mod = 998244353;
int n, m, q, x, y;
int k, a[N], tree[N << 2], tag[N << 2], s[N << 2];
void pushup(int i) {
  tree[i] = (tree[i << 1] + tree[i << 1 | 1]) % mod;
  s[i] = (s[i << 1] + s[i << 1 | 1]) % mod;
}

void pushdown(int i) {
  if (tag[i]) {
    tag[i << 1] = tag[i << 1 | 1] = tag[i];
    tree[i << 1] = tag[i] * s[i << 1] % mod;
    tree[i << 1 | 1] = tag[i] * s[i << 1 | 1] % mod;
    tag[i] = 0;
  }
}

void build(int i, int l, int r) {
  tag[i] = 0;
  if (l == r) {
    tree[i] = s[i] = a[l];
    return;
  }
  int mid = l + (r - l) / 2;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  pushup(i);
}

void update(int i, int l, int r, int m, int n, int k) {
  if (m <= l && r <= n) {
    tree[i] = s[i] * k % mod;
    tag[i] = k;
    return;
  }
  pushdown(i);
  int mid = l + (r - l) / 2;
  if (m <= mid)
    update(i << 1, l, mid, m, n, k);
  if (n > mid)
    update(i << 1 | 1, mid + 1, r, m, n, k);
  //    if(n<=mid) update(i<<1,l,mid,m,n,k);
  //    else if(m>mid) update(i<<1|1,mid+1,r,m,n,k);
  //    else update(i<<1,l,mid,m,mid,k),update(i<<1|1,mid+1,r,mid+1,n,k);
  tree[i] = (tree[i << 1] + tree[i << 1 | 1]) % mod;
}

main() {
  scanf("%d%d", &n, &q);
  a[n] = 1;
  for (int i = n - 1; i >= 1; i--)
    a[i] = a[i + 1] * 10 % mod;
  build(1, 1, n);
  // cout<<"fuck";
  while (q--) {
    scanf("%d%d%d", &x, &y, &k);
    update(1, 1, n, x, y, k);
    printf("%d\\n", tree[1]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const ll mod = 998244353;
int n, m, q, x, y;
int k, a[N], tree[N << 2], tag[N << 2], s[N << 2];
void pushup(int i) {
  tree[i] = (tree[i << 1] + tree[i << 1 | 1]) % mod;
  s[i] = (s[i << 1] + s[i << 1 | 1]) % mod;
}

void pushdown(int i) {
  if (tag[i]) {
    tag[i << 1] = tag[i << 1 | 1] = tag[i];
    tree[i << 1] = tag[i] * s[i << 1] % mod;
    tree[i << 1 | 1] = tag[i] * s[i << 1 | 1] % mod;
    tag[i] = 0;
  }
}

void build(int i, int l, int r) {
  tag[i] = 0;
  if (l == r) {
    tree[i] = s[i] = a[l];
    return;
  }
  int mid = l + (r - l) / 2;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  pushup(i);
}

void update(int i, int l, int r, int m, int n, int k) {
  if (m <= l && r <= n) {
    tree[i] = s[i] * k % mod;
    tag[i] = k;
    return;
  }
  pushdown(i);
  int mid = l + (r - l) / 2;
  if (m <= mid)
    update(i << 1, l, mid, m, n, k);
  if (n > mid)
    update(i << 1 | 1, mid + 1, r, m, n, k);
  //    if(n<=mid) update(i<<1,l,mid,m,n,k);
  //    else if(m>mid) update(i<<1|1,mid+1,r,m,n,k);
  //    else update(i<<1,l,mid,m,mid,k),update(i<<1|1,mid+1,r,mid+1,n,k);
  tree[i] = (tree[i << 1] + tree[i << 1 | 1]) % mod;
}

int main() {
  scanf("%d%d", &n, &q);
  a[n] = 1;
  for (int i = n - 1; i >= 1; i--)
    a[i] = a[i + 1] * 10 % mod;
  build(1, 1, n);
  // cout<<"fuck";
  while (q--) {
    scanf("%d%d%d", &x, &y, &k);
    update(1, 1, n, x, y, k);
    printf("%d\\n", tree[1]);
  }
  return 0;
}
Problem p02538 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

using mint = modint998244353;
const mint inv9 = mint(1) / 9;
struct S {
  mint x, w;
  S(mint x = 0, mint w = 1) : x(x), w(w) {}
};

S op(S a, S b) { return S(a.x * b.w + b.x, a.w * b.w); }
S e() { return S(); }

S mapping(int f, S a) {
  if (f == 0)
    return a;
  return S((a.w - 1) * inv9 * f, a.w);
}

int composition(int f, int g) {
  if (f == 0)
    return g;
  return f;
}

int id() { return 0; }

int main() {
  int n, q;
  cin >> n >> q;
  lazy_segtree<S, op, e, int, mapping, composition, id> t(n);
  rep(i, n) t.set(i, S(1, 10));
  rep(i, q) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    t.apply(l, r, d);
    S ans = t.prod(0, n);
    printf("%d\\n", ans.x.val());
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> s(n, 1);
  rep(i, q) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    for (int j = l; j < r; j++)
      s[j] = d;
    mint ans = 0;
    rep(k, n) {
      ans += s[k];
      if (k < n - 1)
        ans *= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02538 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
#define int long long
int n, q;
int mi[200001], sum[200001];
int summ[1000001], s, t, lazi[1000001];
using namespace std;

void bui(int k, int l, int r) {
  if (l == r) {
    summ[k] = mi[l];
    return;
  }
  int mid = (l + r) >> 1;
  bui(k << 1, l, mid), bui(k << 1 | 1, mid + 1, r);
  summ[k] = (summ[k << 1] + summ[k << 1 | 1]) % 998244353;
  return;
}

void add(int k, int l, int r, int v) {
  lazi[k] = v;
  summ[k] = (((sum[r] - sum[l - 1] + 998244353) % 998244353) * v) % 998244353;
  return;
}

void pushd(int k, int l, int r, int mid) {
  if (lazi[k] == 0)
    return;
  add(k << 1, l, mid, lazi[k]);
  add(k << 1 | 1, mid + 1, r, lazi[k]);
  lazi[k] = 0;
  return;
}

void updata(int k, int l, int r, int v) {
  if (l >= s && r <= t) {
    add(k, l, r, v);
    return;
  }
  int mid = (l + r) >> 1;
  pushd(k, l, r, mid);
  if (s <= mid)
    updata(k << 1, l, mid, v);
  if (mid < t)
    updata(k << 1 | 1, mid + 1, r, v);
  summ[k] = (summ[k << 1] + summ[k << 1 | 1]) % 998244353;
}

signed main() {
  scanf("%lld%lld", &n, &q);
  mi[1] = 1, sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    mi[i] = (mi[i - 1] * 10) % 998244353;
    sum[i] = (mi[i] + sum[i - 1]) % 998244353;
  }
  bui(1, 1, n);
  int num;
  for (int i = 1; i <= q; i++) {
    int ss, tt;
    scanf("%lld%lld%lld", &ss, &tt, &num);
    s = n - tt + 1, t = n - ss + 1;
    updata(1, 1, n, num);
    printf("%lld\\n", summ[1]);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#define int long long
int n, q;
int mi[200001], sum[200001];
int summ[1000001], s, t, lazi[1000001];
using namespace std;

void bui(int k, int l, int r) {
  if (l == r) {
    summ[k] = mi[l];
    return;
  }
  int mid = (l + r) >> 1;
  bui(k << 1, l, mid), bui(k << 1 | 1, mid + 1, r);
  summ[k] = (summ[k << 1] + summ[k << 1 | 1]) % 998244353;
  return;
}

void add(int k, int l, int r, int v) {
  lazi[k] = v;
  summ[k] = ((sum[r] - sum[l - 1]) * v) % 998244353;
  return;
}

void pushd(int k, int l, int r, int mid) {
  if (lazi[k] == 0)
    return;
  add(k << 1, l, mid, lazi[k]);
  add(k << 1 | 1, mid + 1, r, lazi[k]);
  lazi[k] = 0;
  return;
}

void updata(int k, int l, int r, int v) {
  if (l >= s && r <= t) {
    add(k, l, r, v);
    return;
  }
  int mid = (l + r) >> 1;
  pushd(k, l, r, mid);
  if (s <= mid)
    updata(k << 1, l, mid, v);
  if (mid < t)
    updata(k << 1 | 1, mid + 1, r, v);
  summ[k] = (summ[k << 1] + summ[k << 1 | 1]) % 998244353;
}

signed main() {
  scanf("%d%d", &n, &q);
  mi[1] = 1, sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    mi[i] = (mi[i - 1] * 10) % 998244353;
    sum[i] = (mi[i] + sum[i - 1]) % 998244353;
  }
  bui(1, 1, n);
  int num;
  for (int i = 1; i <= q; i++) {
    int ss, tt;
    scanf("%d%d%d", &ss, &tt, &num);
    s = n - tt + 1, t = n - ss + 1;
    updata(1, 1, n, num);
    printf("%d\\n", summ[1]);
  }

  return 0;
}
Problem p02538 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int blo[450], wa[450], s[223456], K[450];

signed main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0, tmp = 0; i < n; i++) {
    s[i] = 1;
    tmp = ((tmp * 10) + 1) % MOD;
    if (i % 450 == 449 || i == n - 1) {
      blo[i / 450] = tmp;
      tmp = 0;
    }
  }
  K[0] = 1;
  for (int i = 1; i < 450; i++)
    K[i] = (K[i - 1] * 10) % MOD;
  const int A = pw(10, 450);
  const int C = (A - 1) * pw(9, MOD - 2) % MOD;
  while (q--) {
    int l, r, d;
    cin >> l >> r >> d;
    l = n - l + 1, r = n - r;
    swap(l, r);
    int res = 0;
    for (int i = 0, CC = 1; i < 450; i++) {
      if (l <= i * 450 && (i + 1) * 450 <= r) {
        wa[i] = d;
        blo[i] = C * d;
      } else if ((i * 450 <= l && l < (i + 1) * 450) ||
                 (i * 450 < r && r <= (i + 1) * 450)) {
        int tmp = 0;
        for (int j = i * 450, t = 0; j < (i + 1) * 450; j++, t++) {
          if (wa[i])
            s[j] = wa[i];
          if (l <= j && j < r)
            s[j] = d;
          tmp = (tmp + s[j] * K[t]) % MOD;
        }
        blo[i] = tmp;
        wa[i] = 0;
      }
      res = (res + blo[i] * CC) % MOD;
      (CC *= A) %= MOD;
    }
    cout << res << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int blo[450], wa[450], s[223456];

signed main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0, tmp = 0; i < n; i++) {
    s[i] = 1;
    tmp = ((tmp * 10) + 1) % MOD;
    if (i % 450 == 449 || i == n - 1) {
      blo[i / 450] = tmp;
      tmp = 0;
    }
  }
  const int A = pw(10, 450);
  while (q--) {
    int l, r, d;
    cin >> l >> r >> d;
    l = n - l + 1, r = n - r;
    swap(l, r);
    int res = 0;
    for (int i = 0, CC = 1; i < 450; i++) {
      if (l <= i * 450 && (i + 1) * 450 <= r) {
        wa[i] = d;
        blo[i] = (pw(10, 450) - 1) * pw(9, MOD - 2) * d % MOD;
      } else if ((i * 450 <= l && l < (i + 1) * 450) ||
                 (i * 450 < r && r <= (i + 1) * 450)) {
        int tmp = 0;
        for (int j = i * 450, C = 1; j < (i + 1) * 450; j++) {
          if (wa[i])
            s[j] = wa[i];
          if (l <= j && j < r)
            s[j] = d;
          tmp = (tmp + s[j] * C) % MOD;
          (C *= 10) %= MOD;
        }
        blo[i] = tmp;
        wa[i] = 0;
      }
      res = (res + blo[i] * CC) % MOD;
      (CC *= A) %= MOD;
    }
    cout << res << endl;
  }
}