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

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

int main() {

  int mod = 998244353;

  int n, k, a, b, l, r;

  cin >> n >> k;

  vector<ll> sum(n + 1, 0);
  vector<ll> ans(n + 1, 0);
  vector<pair<int, int>> pair;

  rep(i, k) {
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }

  // sort(pair.begin(), pair.end());

  sum[0] = 0;
  sum[1] = 1;
  ans[1] = 1;

  for (int i = 2; i <= n; i++) {

    rep(j, k) {
      l = i - pair.at(j).second;
      r = i - pair.at(j).first;
      if (r < 0)
        continue;
      l = max(l, 1);

      ans[i] += sum[r] - sum[l - 1];
      ans[i] %= mod;
    }
    sum[i] = (ans[i] + sum[i - 1]) % mod;
  }

  // for(int x: sum) cout << x <<" ";

  if (ans[n] < 0)
    ans[n] += mod;
  cout << ans[n] << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  ll mod = 998244353;

  ll n, k, a, b, c;
  vector<int> vec(0);

  cin >> n >> k;

  vector<int> ans(n + 1, 0);

  rep(i, k) {
    cin >> a >> b;
    rep(j, b - a + 1) vec.push_back(a + j);
  }
  sort(vec.begin(), vec.end());

  ans[1] = 1;
  rep(i, n + 1) {
    if (i == 0 || i == 1)
      continue;
    for (int x : vec) {
      if (i - x < 0)
        break;

      ans[i] += ans[i - x];
      ans[i] %= mod;
    }
  }

  cout << ans.at(n);
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

// AtCoder :: Beginner Contest 179 :: D - Leaping Tak
// https://atcoder.jp/contests/abc179/tasks/abc179_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{998244353};
const int MAXN{200000};

vector<pair<int, int>> segments;
vector<ll> dp(MAXN + 1, 0);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }

  // Start on [1, 2)
  ll acc{1};
  for (int i{1}; i < N; ++i) {
    acc = (acc + dp[i]) % MOD;
    if (acc > 0) {
      for (auto [sl, sr] : segments) {
        if (i + sl <= N) {
          dp[i + sl] = (dp[i + sl] + acc) % MOD;
        }
        if (i + sr + 1 <= N) {
          dp[i + sr + 1] = (dp[i + sr + 1] - acc) % MOD;
          if (dp[i + sr + 1] < 0) {
            dp[i + sr + 1] += MOD;
          }
        }
      }
    }
  }
  cout << (dp[N] % MOD) << endl;
  return EXIT_SUCCESS;
}


Error: TLE

Fixed submission:

// AtCoder :: Beginner Contest 179 :: D - Leaping Tak
// https://atcoder.jp/contests/abc179/tasks/abc179_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{998244353};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> segments;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }
  sort(segments.begin(), segments.end());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i{1}; i <= N; ++i) {
    for (auto s : segments) {
      if (s.first > N) {
        break;
      }
      for (ll j{s.first}; j <= s.second; j++) {
        if (i + j <= N) {
          dp[i + j] = dp[i + j] + dp[i] % MOD;
        } else {
          break;
        }
      }
    }
  }
  cout << (dp[N] % MOD) << endl;
  return EXIT_SUCCESS;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 998244353;
const long double PI = 3.14159265358979;
const ll MAX = 0;

ll DP[600020];

int main() {

  ll N, K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  rep(i, K) { cin >> L[i] >> R[i]; }
  DP[0] = 1;
  DP[1] = -1;
  rep(i, N) {
    rep(j, K) {
      DP[i + L[j]] += DP[i];
      DP[i + L[j]] %= MOD;
      DP[i + R[j] + 1] -= DP[i];
      DP[i + R[j] + 1] %= MOD;
    }
    DP[i + 1] += DP[i];
    DP[i + 1] %= MOD;
  }
  while (DP[N - 1] < 0) {
    DP[N - 1] += MOD;
  }
  cout << DP[N - 1];
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 998244353;
const long double PI = 3.14159265358979;
const ll MAX = 0;

ll DP[200020];

int main() {

  ll N, K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  rep(i, K) { cin >> L[i] >> R[i]; }
  DP[0] = 1;
  DP[1] = -1;
  rep(i, N) {
    rep(j, K) {
      DP[i + L[j]] += DP[i];
      DP[i + L[j]] %= MOD;
      DP[i + R[j] + 1] -= DP[i];
      DP[i + R[j] + 1] %= MOD;
    }
    DP[i + 1] += DP[i];
    DP[i + 1] %= MOD;
  }
  while (DP[N - 1] < 0) {
    DP[N - 1] += MOD;
  }
  cout << DP[N - 1];
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[200001];
long long pre[200001];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> S;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    S.push_back({l, r});
  }
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] % mod + dp[i - 1] % mod) % mod;
    for (int j = 0; j < k; j++) {
      int l = S[j].first;
      int r = S[j].second;
      if (i + l <= n) {
        dp[i + l] += dp[i];
        dp[i + l] %= mod;
      }
      if (i + r + 1 <= n) {
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + mod) % mod;
        dp[i + r + 1] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[200001];
long long pre[200001];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> S;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    S.push_back({l, r});
  }
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] % mod + dp[i - 1] % mod) % mod;
    for (int j = 0; j < k; j++) {
      int l = S[j].first;
      int r = S[j].second;
      if (i + l <= n) {
        dp[i + l] += dp[i];
        dp[i + r + 1] %= mod;
      }
      if (i + r + 1 <= n) {
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + mod) % mod;
        dp[i + r + 1] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <utility>
#include <vector>

int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;

  std::vector<std::pair<int, int>> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    std::cin >> l >> r;
    s.push_back(std::pair<int, int>(l, r));
  }

  int mod = 998244353;

  std::vector<long> dp(n + 1, 0);
  std::vector<long> dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto d : s) {
      long l = std::max(i - d.second, 1);
      long r = i - d.first;
      if (r < 1) {
        continue;
      }

      dp[i] += dpsum[r] - dpsum[l - 1];
      dp[i] %= mod;
    }

    dpsum[i] = dpsum[i - 1] + dp[i];
  }

  std::cout << dp[n] << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;

  std::vector<int> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    std::cin >> l >> r;

    for (int j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }
  std::sort(s.begin(), s.end());

  int x = 998244353;

  std::vector<long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int d : s) {
      int j = i + d;
      if (j > n) {
        break;
      }
      dp[j] += dp[i];
    }
  }

  std::cout << dp[n] % x << std::endl;

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

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

const ll INF = 1LL << 60;
const ll MOD = 998244353;
ll dp[200020];

int main() {
  int N, K;
  cin >> N >> K;
  int l[10], r[10];
  REP(i, K) cin >> l[i] >> r[i];

  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    REP(j, K) {
      if (i + l[j] <= N)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      if (i + r[j] + 1 <= N) {
        dp[i + r[j] + 1] = dp[i + r[j] + 1] - dp[i];
        if (dp[i + r[j] + 1] < 0)
          dp[i + r[j] + 1] += MOD;
      }
    }
    //    REP(i,N+1) cout << dp[i] << " ";
    //    cout << endl;
  }
  cout << dp[N] << endl;
}


Error: 0

Fixed submission:

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

const ll INF = 1LL << 60;
const ll MOD = 998244353;
ll dp[200020];

int main() {
  int N, K;
  cin >> N >> K;
  int l[10], r[10];
  REP(i, K) cin >> l[i] >> r[i];

  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    REP(j, K) {
      if (i + l[j] <= N)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      if (i + r[j] + 1 <= N)
        dp[i + r[j] + 1] = dp[i + r[j] + 1] - dp[i];
      if (dp[i + r[j] + 1] < 0)
        dp[i + r[j] + 1] += MOD;
    }
    //    REP(i,N+1) cout << dp[i] << " ";
    //    cout << endl;
  }
  cout << dp[N] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 998244353;
long long dp[N] = {};
long long sum[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> L[i] >> R[i];
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      dp[i] = (dp[i] + sum[max(0, i - L[j])] - sum[max(0, i - R[j] - 1)]) % mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  dp[n] %= mod;
  if (dp[n] < 0)
    dp[n] += mod;
  cout << dp[n] << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int dp[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> L[i] >> R[i];
  dp[1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = max(1, i - R[j]); k <= i - L[j]; k++)
        dp[i] = (dp[i] + dp[k]) % mod;
  cout << dp[n] << '\\n';
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 1e9
#define MOD 998244353
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pii> lr(K);
  for (int i = 0; i < K; i++) {
    cin >> lr[i].first >> lr[i].second;
    lr[i].second++;
  }

  vector<ll> dp(N + 1, 0);
  dp[0] = 1;
  dp[1] = -1;

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      dp[i] += dp[i - 1];
      dp[i] %= MOD;
    }
    for (int j = 0; j < K; j++) {
      if (i + lr[j].first < N) {
        dp[i + lr[j].first] += dp[i];
        dp[i + lr[j].first] %= MOD;
      }
      if (i + lr[j].second < N) {
        dp[i + lr[j].second] += (MOD - dp[i]);
        dp[i + lr[j].second] %= MOD;
      }
    }
  }

  cout << dp[N - 1] << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 1e9
#define MOD 998244353
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pii> lr(K);
  for (int i = 0; i < K; i++) {
    cin >> lr[i].first >> lr[i].second;
  }

  vector<ll> dp(N + 1, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      for (int d = lr[j].first; d <= min(N - i, lr[j].second); d++) {
        dp[i + d] += dp[i];
        dp[i + d] %= MOD;
      }
    }
  }

  cout << dp[N] << endl;

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

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

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<long long> dp(n + 1);
  vector<long long> dps(n + 1);
  dp[1] = dps[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int li = i - r[j];
      li = max(li, 1);
      int ri = i - l[j];
      if (ri < 1)
        continue;
      dp[i] = (dp[i] + dps[ri] - dps[li - 1]) % mod;
    }
    dps[i] = (dps[i - 1] + dp[i]) % mod;
  }
  cout << (dp[n] + mod) % mod << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    milkshake();

  return 0;
}


Error: TLE

Fixed submission:

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

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> t(n + 1);
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      t[i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (t[i])
      s.push_back(i);
  }

  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)s.size(); j++) {
      if (i - s[j] < 1)
        continue;
      dp[i] = (dp[i] + dp[i - s[j]]) % mod;
    }
  }
  cout << dp[n] % mod << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    milkshake();

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

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
  int n, k;
  cin >> n >> k;
  ar<int, 2> arr[n];
  for (int i = 0; i < k; i++)
    cin >> arr[i][0] >> arr[i][1];
  vector<int> dp(n);
  dp[0] = 1, dp[1] = -1;
  for (int i = 0; i < n; i++) {
    if (i > 0)
      dp[i] = (dp[i] + dp[i - 1]) % MOD;
    for (int j = 0; j < k; j++) {
      auto [l, r] = arr[j];
      if (i + l < n)
        dp[i + l] = (dp[i + l] + dp[i]) % MOD;
      if (i + r + 1 < n)
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + MOD) % MOD;
    }
  }
  cout << dp[n - 1] << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int tc;
  tc = 1;
  for (int t = 1; t <= tc; t++) {
    // cout << "Case #" << t  << ": ";
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1), a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      a.push_back(j);
  }
  sort(a.begin(), a.end());
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a.size() && i + a[j] <= n; j++) {
      dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % MOD;
    }
  }
  cout << dp[n] << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int tc;
  tc = 1;
  for (int t = 1; t <= tc; t++) {
    // cout << "Case #" << t  << ": ";
    solve();
  }
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
// cout << setprecision(20) <<

#define SEG_LEN (200010)

ll seg[SEG_LEN * 2] = {0};

// one point
ll get(ll ind) {
  ind += SEG_LEN;
  ll sum = 0;
  sum += seg[ind];
  while (true) {
    ind /= 2;
    if (ind == 0)
      break;
    sum += seg[ind];
    sum %= MOD;
  }
  return sum;
}

// range
void add(ll l, ll r, ll x) {
  l += SEG_LEN;
  r += SEG_LEN;
  while (l < r) {
    if (l % 2 == 1) {
      seg[l] %= MOD;
      seg[l] += x;
      seg[l] %= MOD;
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      seg[r - 1] %= MOD;
      seg[r - 1] += x;
      seg[r - 1] %= MOD;
      r--;
    }
    r /= 2;
  }
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }

  add(1, 2, 1);
  for (int i = 1; i < n; ++i) {
    for (auto p : v) {
      ll x = get(i);
      ll l = p.first + i;
      if (l > n)
        continue;
      ll r = min(n + 1, p.second + i + 1);
      if (r - l <= 0)
        continue;
      add(l, r, x);
    }
  }
  // for (int i = 1; i <= n; ++i) {
  //   cout << get(i) << " ";
  // }
  // cout << endl;
  cout << get(n) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
// cout << setprecision(20) <<

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }

  vector<ll> a(n + 1, 0);
  a[1] = 1;
  for (int i = 1; i < n; ++i) {
    // cout << "at i:" << i << endl;
    for (auto p : v) {
      for (int j = i + p.first; j <= min(i + p.second, n); ++j) {
        // cout << "j : " << j << endl;
        a[j] += a[i];
        a[j] %= MOD;
      }
    }
    // for (int j = 1; j <= n; ++j) {
    //     cout << a[j] << " ";
    // }
    // cout << endl;
  }
  cout << a[n] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  for (ll i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  vector<ll> dp(2e5 + 20, 0);
  vector<ll> sum(2e5 + 20, 0);
  sum[1] = 1;
  dp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 0; j < k; j++) {
      ll li = i - r[j];
      ll ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, (ll)1);
      dp[i] += (sum[ri] - sum[li - 1] + MOD);
      dp[i] %= MOD;
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= MOD;
  }
  cout << dp[n] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> data(k);
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    r -= l;
    data[i] = {l, r};
  }
  vector<ll> dp(2e5 + 20, 0);
  dp[1] = 1;
  for (ll i = 1; i < 2e5; i++) {
    if (dp[i] == 0)
      continue;
    for (ll j = 0; j < k; j++) {
      for (ll l = 0; l <= data[j].second; l++) {
        if (i + data[j].first + l >= 2e5)
          break;
        dp[i + data[j].first + l] = (dp[i + data[j].first + l] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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() {
  ll N;
  ll K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  vector<mint> dp(N + 1, 0);
  vector<mint> acc_sum(N + 1, 0);

  dp[1] = 1;
  acc_sum[1] = 1;

  for (int i = 2; i <= N; ++i) {
    for (int j = 0; j < K; j++) {
      int rj = i - L[j];
      int lj = i - R[j];
      if (rj < 0)
        continue;
      lj = max(lj, 1);
      dp[i] += (acc_sum[rj] - acc_sum[lj - 1]);
    }
    acc_sum[i] = (acc_sum[i - 1] + dp[i]);
  }
  cout << dp[N] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

ll solve(ll loc, vector<ll> &pattern, vector<ll> action) {
  ll cnt(0);

  if (loc == 1) {
    return 1;
  }
  if (pattern[loc] == -1) {
    for (ll i = 0; i < action.size(); ++i) {
      if (loc - action[i] > 0) {
        cnt += (solve(loc - action[i], pattern, action) % 998244353);
        cnt %= 998244353;
      }
    }
    pattern[loc] = cnt;
    return cnt;
  } else {
    return pattern[loc];
  }
}

int main() {
  ll N;
  ll K;
  ll cnt(0);
  cin >> N >> K;
  ll L[K];
  ll R[K];

  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
  }

  vector<ll> pattern_map(N, -1);
  vector<ll> fill_map(N + 1, -1);
  vector<ll> action_map;

  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) {
      if (fill_map[j] == -1) {
        action_map.push_back(j);
        fill_map[j] = 0;
      }
    }
  }
  for (ll i = 0; i < action_map.size(); ++i) {
    if (N - action_map[i] > 0) {
      cnt += (solve(N - action_map[i], pattern_map, action_map) % 998244353);
      cnt %= 998244353;
    }
  }
  cout << cnt % 998244353 << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> ans(n + 10, 0), sum(n + 10, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[0] = 1;
  sum[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - r[j] - 1 >= 0) {
        ans[i] -= sum[i - r[j] - 1];
      }
      if (i - l[j] >= 0) {
        ans[i] += sum[i - l[j]];
      }
    }
    ans[i] %= MOD;
    sum[i] += sum[i - 1] + ans[i];
    // for(int j = 0; j < n; j++) {
    //   cout << ans[j] << " ";
    // }
    // cout << '\\n';
  }
  if (ans[n - 1] < 0) {
    ans[n - 1] += MOD;
  }
  cout << ans[n - 1] % MOD << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> ans(n + 10, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[0] = 1;
  ll now = 0;
  for (int i = 0; i < n; i++) {
    now += ans[i];
    if (now > 0) {
      for (int j = 0; j < k; j++) {
        ans[l[j] + i] += now;
        ans[min(r[j] + i + 1, n)] -= now;
      }
    }
    ans[i] %= MOD;
    // for(int j = 0; j < n; j++) {
    //   cout << ans[j] << " ";
    // }
    // cout << '\\n';
  }
  cout << ans[n - 1] % MOD << endl;
  return 0;
}