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

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

long long mod = 998244353;

int main() {
  long long n, k;
  cin >> n >> k;

  vector<long long> l(k);
  vector<long long> r(k);
  for (long long i = 0; i < k; i++)
    cin >> l[i] >> r[i];

  vector<long long> dp(n, 0);
  dp[0] = 1;
  dp[1] = -1;

  for (long long i = 0; i < n; i++) {
    if (i > 0)
      dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (long long j = 0; j < k; j++) {
      if (i + l[j] < n) {
        dp[i + l[j]] += dp[i];
        dp[i + l[j]] %= mod;
      }

      if (i + r[j] + 1 < n) {
        dp[i + r[j] + 1] -= dp[i];
        dp[i + r[j] + 1] += mod;
        dp[i + r[j] + 1] %= mod;
      }
    }
  }

  cout << dp[n - 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

long long mod = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;

  vector<long long> slide;
  set<long long> T;

  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;

    for (long long j = l; j <= r; j++) {
      T.insert(j);
    }
  }

  set<long long>::iterator it;
  for (it = T.begin(); it != T.end(); it++)
    slide.push_back(*it);

  vector<long long> dp(n, 0);

  dp[0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < slide.size(); j++) {
      if (i - slide[j] >= 0) {
        dp[i] += dp[i - slide[j]];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

constexpr int mod = 998244353;

std::vector<int> sums;

int calc(int n, const std::vector<std::pair<int, int>> &lrs,
         std::vector<int> &dp) {
  for (std::size_t i = 0; i < lrs.size(); ++i) {
    const auto &p = lrs[i];
    if (n - p.second - 1 > 0) {
      sums[i] -= dp[n - p.second - 1];
      if (sums[i] < 0)
        sums[i] += mod;
      sums[i] %= mod;
    }
    if (n - p.first > 0) {
      sums[i] += dp[n - p.first];
      sums[i] %= mod;
    }
  }

  int result = 0;
  for (std::size_t i = 0; i < lrs.size(); ++i) {
    result += sums[i];
    result %= mod;
  }
  dp[n] = result;
  return result;
}

int solve(int n, int k, std::vector<std::pair<int, int>> &lrs) {
  std::sort(lrs.begin(), lrs.end());

  sums = std::vector<int>(k);

  std::vector<int> dp(n + 1, -1);
  dp[1] = 1;
  for (int i = 2; i < n; ++i) {
    calc(i, lrs, dp);
  }
  return calc(n, lrs, dp);
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<std::pair<int, int>> lrs(k);
  for (auto &p : lrs) {
    std::cin >> p.first >> p.second;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, k, lrs) << std::endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

constexpr int mod = 998244353;

int calc(int n, const std::vector<int> &s, std::vector<int> &dp) {
  int result = 0;
  for (auto d : s) {
    if (n - d <= 0)
      break;
    if (dp[n - d] < 0) {
      dp[n - d] = calc(n - d, s, dp);
    }
    result += dp[n - d];
    result %= mod;
  }
  dp[n] = result;
  return result;
}

int solve(int n, int k, std::vector<int> &s) {
  sort(s.begin(), s.end());
  std::vector<int> dp(n + 1, -1);
  dp[1] = 1;
  return calc(n, s, dp);
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> s;
  for (int i = 0; i < k; ++i) {
    int left, right;
    std::cin >> left >> right;
    for (int j = left; j <= right; ++j) {
      s.push_back(j);
    }
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, k, s) << std::endl;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long, long long>
#define ppp pair<long long, pair<long long, long long>>
#define f first
#define s second
#define pd pair<double, long long>
ll barr[200100], M = 998244353;
void solveTestCase() {
  ll n, i, j, k, l;
  cin >> n >> k;
  vector<pp> arr(k + 1);
  for (i = 1; i <= k; i++)
    cin >> arr[i].f >> arr[i].s;
  barr[1] = 1;
  barr[2] = -1;
  for (i = 1; i <= n; i++) {
    barr[i] += barr[i - 1];
    barr[i] %= M;
    if (!barr[i])
      continue;
    for (j = 1; j <= k; j++) {
      if (i + arr[j].f <= n) {
        barr[i + arr[j].f] += barr[i];
        barr[i + arr[j].f] %= M;
      }
      if (i + arr[j].s + 1 <= n) {
        barr[i + arr[j].s + 1] += (M - barr[i]);
        barr[i + arr[j].s + 1] %= M;
      }
    }
  }
  cout << barr[n] << '\\n';
}
int main() {
  ll t, n, i, j, k, l, m;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll p;
  t = 1;
  // cin>>t;
  for (ll T = 1; T <= t; T++) {
    solveTestCase();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long, long long>
#define ppp pair<long long, pair<long long, long long>>
#define f first
#define s second
#define pd pair<double, long long>
ll barr[200100], M = 998244353;
void solveTestCase() {
  ll n, i, j, k, l;
  cin >> n >> k;
  vector<pp> arr(k + 1);
  for (i = 1; i <= k; i++)
    cin >> arr[i].f >> arr[i].s;
  barr[1] = 1;
  barr[2] = -1;
  for (i = 1; i <= n; i++) {
    barr[i] += barr[i - 1];
    barr[i] %= M;
    if (!barr[i])
      continue;
    for (j = 1; j <= k; j++) {
      barr[i + arr[j].f] += barr[i];
      barr[i + arr[j].f] %= M;
      barr[i + arr[j].s + 1] += (M - barr[i]);
      barr[i + arr[j].s + 1] %= M;
    }
  }
  cout << barr[n] << '\\n';
}
int main() {
  ll t, n, i, j, k, l, m;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll p;
  t = 1;
  // cin>>t;
  for (ll T = 1; T <= t; T++) {
    solveTestCase();
  }
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

const ll MODULO = 998244353L;
ll mod_minus(ll x, ll modval) {
  if (x >= 0) {
    return x % modval;
  } else {
    ll mm = ((-x) % modval);
    if (mm == 0) {
      return 0;
    } else {
      return modval - mm;
    }
  }
}
ll mod(ll x) { return mod_minus(x, MODULO); }

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> dp(200003, 0);
  vector<ll> left(K);
  vector<ll> right(K);
  vector<ll> exist(200003, 0);
  for (ll i = 0; i < K; i++) {
    cin >> left[i] >> right[i];
    for (ll j = left[i]; j <= right[i]; j++) {
      exist[j] = 1;
    }
  }

  for (ll i = 2; i <= N; i++) {
    dp[i] = dp[i - 1] - exist[i - 2] + exist[i - 1];
    for (ll j = 0; j < K; j++) {
      ll l = left[j];
      ll r = right[j];
      if (i - r - 1 >= 1) {
        dp[i] = mod(dp[i] - dp[i - r - 1]);
      }
      if (i - l >= 1) {
        dp[i] = mod(dp[i] + dp[i - l]);
      }
    }
  }
  print(dp[N]);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> dp(200003, 0);
  vector<ll> exist(200003, 0);
  vector<ll> moves;
  for (ll i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      // exist[j] = 1;
      moves.push_back(j);
    }
  }
  sort(moves.begin(), moves.end());

  dp[1] = 1;
  for (ll i = 1; i <= N; i++) {
    for (auto j : moves) {
      if (i + j > N) {
        break;
      }
      dp[i + j] = (dp[i + j] + dp[i]) % 998244353;
    }
  }
  print(dp[N]);
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

// O(nk)
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#define l first
#define r second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
const ll mod = 998244353;
int n, k;
ll f[N], s[N];
pii a[N];
int main() {
  IO;
  int minpos = 1e9;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].l >> a[i].r;
    minpos = min(minpos, a[i].l);
  }
  f[1] = 1;
  s[1] = 1;
  for (int i = 1 + minpos; i <= n; i++) {
    for (int j = 1; j <= k; j++)
      f[i] = (f[i] + s[max(0, i - a[j].l)] - s[max(0, i - a[j].r - 1)]) % mod;
    ;
    s[i] = (s[i - 1] + f[i]) % mod;
  }
  cout << (f[n] + mod) % mod << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie();                                                                   \\
  cout.tie(0)
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 200010;
const ll MOD = 998244353;
int n, k;
ll dp[N];
struct node {
  int l, r;
} a[N];
int main() {
  IO;
  cin >> n >> k;
  int minpos = 1e9;
  for (int i = 1; i <= k; i++) {
    cin >> a[i].l >> a[i].r;
    minpos = min(minpos, a[i].l);
  }
  dp[1] = 1;
  for (int i = 2; i <= minpos; i++)
    dp[i] = 0;
  for (int i = 1 + minpos; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      for (int m = a[j].l; m <= a[j].r; m++) {
        dp[i] = (dp[i] + dp[max(i - m, 0)]) % MOD;
      }
    }
  }
  cout << (dp[n] + MOD) % MOD << '\\n';
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, k;
  cin >> n >> k;
  int mod = 998244353;
  vector<pair<int, int>> steps;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    steps.push_back({x, y});
  }

  sort(steps.begin(), steps.end());
  vector<int> dp(n);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int l = i - steps[j].second;
      int r = i - steps[j].first;
      if (r >= 0) {
        dp[i] = (dp[i] + dp[r]) % mod;
      }
      if (l > 0) {
        dp[i] = (dp[i] - dp[l - 1] + mod) % mod;
      }
    }

    if (i != n - 1) {
      dp[i] = (dp[i] + dp[i - 1]) % mod;
    }
  }

  cout << dp[n - 1];

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, k;
  cin >> n >> k;
  int mod = 998244353;
  vector<pair<int, int>> steps;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    steps.push_back({x, y});
  }

  sort(steps.begin(), steps.end());
  vector<int> dp(n);
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = i - steps[j].second;
      int r = i - steps[j].first;
      if (r >= 0) {
        dp[i] = (dp[i] + dp[r]) % mod;
      }
      if (l > 0) {
        dp[i] = (dp[i] - dp[l - 1] + mod) % mod;
      }
    }

    if (i != n - 1) {
      dp[i] = (dp[i] + dp[i - 1]) % mod;
    }
  }

  cout << dp[n - 1];

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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 998244353
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pii> cnt(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    cnt[i] = make_pair(l, r);
  }
  vi dp(n);
  dp[0] = 1;
  dp[1] = -1;
  rep(i, n) {
    if (i > 0)
      (dp[i] += dp[i - 1]) %= mod;
    rep(j, k) {
      int l = cnt[j].first, r = cnt[j].second;
      if (i + l < n)
        (dp[i + l] += dp[i]) %= mod;
      if (i + r + 1 < n)
        (dp[i + r + 1] += -dp[i] + mod) %= mod;
    }
  }
  cout << dp[n - 1] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     //sqrt pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // dequef
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 998244353
using ll = long long;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vi cnt(n + 2);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    cnt[l]++;
    cnt[r + 1]--;
  }
  rep(i, n) cnt[i + 1] += cnt[i];
  set<int> check;
  rep(i, n) if (cnt[i + 1] > 0) check.insert(i + 1);
  vi dp(n + 1);
  dp[0] = 1;
  rep(i, n) {
    for (auto a : check) {
      if (i + a < n)
        (dp[i + a] += dp[i]) %= mod;
      else
        break;
    }
  }
  cout << dp[n - 1] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>

const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 998244353;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
const int maxm = 100 + 10;
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

ll dp[maxn];
int vis[maxn];
int n, k;
int main() {
  cin >> n >> k;
  vector<pii> e;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    e.push_back(make_pair(l, r));
  }
  sort(e.begin(), e.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < e.size(); j++) {
      int l = e[j].fi;
      int r = e[j].se;
      if (i - l < 0) {
        break;
      } else if (i - r >= 1)
        dp[i] = (dp[i] + dp[i - l] - dp[i - r - 1] + mod) % mod;
      else
        dp[i] = (dp[i] + dp[i - l]) % mod;
    }
    dp[i] = (dp[i] + dp[i - 1]) % mod;
  }
  cout << (dp[n] - dp[n - 1] + mod) % mod << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define nl '\\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a, b) memset(a, b, sizeof a)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a, b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
// #pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 998244353, inf = 0x3f3f3f;
ll v[N], dp[N];
vector<int> a;

int dfs(ll n) {
  if (~dp[n])
    return dp[n];

  dp[n] = 0;
  for (auto u : a)
    if (u <= n)
      dp[n] = (dp[n] + dfs(n - u)) % mod;
    else
      break;
  return dp[n];
}

int main() {
  IOS;
  ll n, k, ans = 0;
  cin >> n >> k;
  rep1(i, k) {
    int l, r;
    cin >> l >> r;
    v[l]++;
    v[r + 1]--;
  }
  rep1(i, n) {
    dp[i] = -1;
    v[i] += v[i - 1];
    if (v[i])
      a.pb(i);
  }

  dp[0] = 1;
  cout << dfs(n - 1) << nl;

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

#include <bits/stdc++.h>
#define ll long long
#define st first
#define sc second
#define pb push_back

using namespace std;

const int maxn = 1e6 + 69;
const ll mod = 998244353;

int a[maxn][10];
ll dp[maxn];
ll st[4 * maxn];

void update(int id, int l, int r, int pos, ll val) {
  if (pos < l || pos > r)
    return;
  if (l == r) {
    st[id] += val;
    st[id] %= mod;
    return;
  }
  int mid = (l + r) / 2;
  update(id * 2, l, mid, pos, val);
  update(id * 2 + 1, mid + 1, r, pos, val);
  st[id] = (st[id * 2] + st[id * 2 + 1]) % mod;
}

ll get(int id, int l, int r, int u, int v) {
  if (v < l || u > r)
    return 0;
  if (u <= l && r <= v) {
    return st[id];
  }
  int mid = (l + r) / 2;
  return (get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v)) % mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> p;
  for (int i = 1; i <= t; i++) {
    int l, r;
    cin >> l >> r;
    p.pb({l, r});
  }
  sort(p.begin(), p.end());
  update(1, 1, n, 1, 1);
  for (int i = 2; i <= n; i++) {
    for (int k = 0; k < t; k++) {
      int l = p[k].st;
      int r = p[k].sc;
      if (i < l)
        break;
      if (r < i) {
        if (i - l < 1)
          continue;
        int lf = max(i - l, 1);
        int rg = max(i - r, 1);
        ll cur = get(1, 1, n, rg, lf);
        update(1, 1, n, i, cur);
      } else if (l <= i && i <= r) {
        if (i - l < 1)
          continue;
        int lf = max(i - l, 1);
        ll cur = get(1, 1, n, 1, lf);
        update(1, 1, n, i, cur);
      }
    }
  }
  cout << get(1, 1, n, n, n);
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define st first
#define sc second
#define pb push_back

using namespace std;

const int maxn = 1e6 + 69;
const ll mod = 998244353;

int a[maxn][10];
ll dp[maxn];

vector<int> s;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, t;
  cin >> n >> t;
  for (int i = 1; i <= t; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      s.pb(j);
  }
  sort(s.begin(), s.end());
  dp[1]++;
  for (int i = 1; i <= n; i++) {
    for (auto j : s) {
      if (j >= i)
        break;
      if (i - j >= 1) {
        dp[i] += dp[i - j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n] % mod;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 10;
int a[N];
int f[N];
struct node {
  int s[2];
} T[N];
bool cmp(node t1, node t2) { return t1.s[0] < t2.s[0]; }
int main() {
  f[1] = 1;
  f[2] = -1;
  a[1] = 1;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> T[i].s[0] >> T[i].s[1];
  // for(int i=1;i<=k;++i){
  //     cout<<T[i].s[0]<<' '<<T[i].s[1]<<endl;
  // }
  sort(T + 1, T + k + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (i > 2)
      f[i] = (f[i - 1] + a[i]) % mod;
    else if (i == 2)
      f[i] = a[i];
    // else if(i==2)f[2]=f[i-1]+f[i];
    for (int j = 1; j <= k; ++j) {
      if (i + T[j].s[0] <= n)
        (a[i + T[j].s[0]] += f[i]) %= mod;
      if (i + T[j].s[1] + 1 <= n)
        (((a[i + T[j].s[1] + 1] -= f[i]) %= mod) += mod) %= mod;
    }
  }
  // for(int i=1;i<=n;++i){
  //     cout<<f[i]<<' ';
  // }
  // cout<<endl;
  cout << f[n] << endl;
  // int sum=0;
  // for(int i=1;i<=n;i++)sum+=f[i];
  // cout<<sum<<endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 10;
int a[N];
int f[N];
struct node {
  int s[2];
} T[N];
bool cmp(node t1, node t2) { return t1.s[0] < t2.s[0]; }
int main() {
  f[1] = 1;
  f[2] = -1;
  a[1] = 1;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> T[i].s[0] >> T[i].s[1];
  // for(int i=1;i<=k;++i){
  //     cout<<T[i].s[0]<<' '<<T[i].s[1]<<endl;
  // }
  sort(T + 1, T + k + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (i > 2)
      f[i] = (f[i - 1] + a[i]) % mod;
    else if (i == 2)
      f[i] = a[i];
    // else if(i==2)f[2]=f[i-1]+f[i];
    for (int j = 1; j <= k; ++j) {
      if (i + T[j].s[0] <= n)
        (a[i + T[j].s[0]] += f[i]) %= mod;
      if (i + T[j].s[1] + 1 <= n)
        (((a[i + T[j].s[1] + 1] -= f[i]) %= mod) += mod) %= mod;
    }
  }
  // for(int i=1;i<=n;++i){
  //     cout<<f[i]<<' ';
  // }
  // cout<<endl;
  cout << f[n] << endl;
  // int sum=0;
  // for(int i=1;i<=n;i++)sum+=f[i];
  // cout<<sum<<endl;
}