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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \\
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int main() {
  int64 nn, kk;
  cin >> nn >> kk;
  vector<pair<int64, int64>> memo(kk);
  for (int64 ii = 0; ii < kk; ii++) {
    cin >> memo[ii].first >> memo[ii].second;
  }
  vector<int64> vv(3 * nn, 0), table(3 * nn, 0);
  vv[0] = 1;
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    vv[(*ite).first] += vv[0];
    if ((*ite).second + 1 < nn) {
      vv[(*ite).second + 1] -= vv[0];
    }
  }

  for (int64 ii = 1; ii < nn; ii++) {
    vv[ii] += table[ii - 1];
    while (vv[ii] < 0) {
      vv[ii] += mod;
    }
    vv[ii] %= mod;
    table[ii] = vv[ii];
    for (auto ite = memo.begin(); ite != memo.end(); ite++) {
      if (ii + (*ite).first < nn) {
        vv[ii + (*ite).first] += table[ii];
        vv[ii + (*ite).first] %= mod;
      }
      if (ii + (*ite).second + 1 < nn) {
        vv[ii + (*ite).second + 1] -= table[ii];
        while (vv[ii + (*ite).second + 1] < 0) {
          vv[ii + (*ite).second + 1] += mod;
        }
        vv[ii + (*ite).second + 1] %= mod;
      }
    }
  }

  cout << table[nn - 1] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \\
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int main() {
  int64 nn, kk, ll, rr;
  cin >> nn >> kk;
  vector<pair<int64, int64>> memo(kk);
  for (int64 ii = 0; ii < kk; ii++) {
    cin >> memo[ii].first >> memo[ii].second;
  }
  vector<int64> vv(nn, 0), table(nn, 0);
  vv[0] = 1;
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    vv[(*ite).first] += vv[0];
    if ((*ite).second + 1 < nn) {
      vv[(*ite).second + 1] -= vv[0];
    }
  }

  for (int64 ii = 1; ii < nn; ii++) {
    vv[ii] += table[ii - 1];
    if (vv[ii] < 0) {
      vv[ii] += mod;
    }
    vv[ii] %= mod;
    table[ii] = vv[ii];
    for (auto ite = memo.begin(); ite != memo.end(); ite++) {
      if (ii + (*ite).first < nn) {
        vv[ii + (*ite).first] += table[ii];
      }
      if (ii + (*ite).second + 1 < nn) {
        vv[ii + (*ite).second + 1] -= table[ii];
      }
    }
  }

  cout << table[nn - 1] << endl;
  return 0;
}