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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define test(a)                                                                \\
  cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl

constexpr int INF = 1e9 + 7;
constexpr ll INFL = 9 * 1e18;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
} // 桁数
template <typename T> inline T SUM(vector<T> vec) {
  return accumulate(all(vec), (T)0);
} // vectorの中身を全部足す
template <typename T> inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
} // 各桁の和
template <typename T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
} // 最大公約数
template <typename T> inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
} // 最小公倍数
template <typename T> inline T power(T a, T b) {
  T tmp = 1;
  rep(i, b) { tmp *= a; }
  return tmp;
} // 累乗
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline void print(T &&x) {
  cout << setprecision(32) << x << endl;
}

constexpr int SIZE = 200020;
int s[SIZE];
ll dp[SIZE];
int kA[SIZE];
pair<int, int> lr[10];
// TODO: write
int main() {
  ll waru = 998244353;
  int n, k;
  cin >> n >> k;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    lr[i] = (mp(l, r));
    for (int j = l; j <= r; ++j) {
      s[j] = 1;
    }
  }

  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    rep(j, k) {
      if (i - lr[j].se > 0) {
        kA[j] -= dp[i - lr[j].se];
        kA[j] %= waru;
        if (kA[j] < 0)
          kA[j] += waru;
        // test(i);
        // test(lr[j].se);
        // test(kA[j]);
      }
      if (i - lr[j].fi > 0) {
        kA[j] += dp[i - lr[j].fi];
        kA[j] %= waru;
        // test(i-lr[j].fi);
        // test(kA[j]);
      }
      dp[i] += kA[j];
      dp[i] %= waru;
    }
  }

  // for(int i = 2;i <= n;++i){
  //   rep(j,i){
  //     if(s[j+1]){
  //       dp[i] += dp[i-j-1];
  //       dp[i] %= waru;
  //     }
  //   }
  // }

  print(dp[n]);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define test(a)                                                                \\
  cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl

constexpr int INF = 1e9 + 7;
constexpr ll INFL = 9 * 1e18;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
} // 桁数
template <typename T> inline T SUM(vector<T> vec) {
  return accumulate(all(vec), (T)0);
} // vectorの中身を全部足す
template <typename T> inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
} // 各桁の和
template <typename T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
} // 最大公約数
template <typename T> inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
} // 最小公倍数
template <typename T> inline T power(T a, T b) {
  T tmp = 1;
  rep(i, b) { tmp *= a; }
  return tmp;
} // 累乗
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline void print(T &&x) {
  cout << setprecision(32) << x << endl;
}

// TODO: write
int main() {
  ll waru = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> s(n + 1, 0);
  vector<ll> dp(n + 1, 0);
  vector<pair<int, int>> lr(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    lr[i] = (mp(l, r));
    for (int j = l; j <= r; ++j) {
      s[j] = 1;
    }
  }

  dp[1] = 1;
  vector<int> kA(k, 0);
  for (int i = 2; i <= n; ++i) {
    rep(j, k) {
      if (i - lr[j].se > 0) {
        kA[j] -= dp[i - lr[j].se];
        kA[j] %= waru;
        if (kA[j] < 0)
          kA[j] += waru;
        // test(i);
        // test(lr[j].se);
        // test(kA[j]);
      }
      if (i - lr[j].fi > 0) {
        kA[j] += dp[i - lr[j].fi];
        kA[j] %= waru;
        // test(i-lr[j].fi);
        // test(kA[j]);
      }
      dp[i] += kA[j];
      dp[i] %= waru;
    }
  }

  // for(int i = 2;i <= n;++i){
  //   rep(j,i){
  //     if(s[j+1]){
  //       dp[i] += dp[i-j-1];
  //       dp[i] %= waru;
  //     }
  //   }
  // }

  print(dp[n]);
  return 0;
}