Problem p02549 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  long n, k;
  cin >> n >> k;
  vector<pll> data(k);
  rep(i, k) cin >> data.at(i).first >> data.at(i).second;
  vector<long> dp(200010, 0);
  vector<long> imos(200010, 0);
  dp.at(1) = 1;
  long acm = 0;
  REP(v, 1, n) {
    if (v == 1) {
      rep(i, k) {
        imos.at(v + data.at(i).first) += 1;
        imos.at(v + data.at(i).second + 1) -= 1;
      }
    } else {
      acm += imos.at(v);
      acm %= MOD;
      dp.at(v) = acm;
      rep(i, k) {
        imos.at(v + data.at(i).first) += acm;
        imos.at(v + data.at(i).first) % MOD;
        imos.at(v + data.at(i).second + 1) -= acm;
        imos.at(v + data.at(i).second + 1) += MOD;
        imos.at(v + data.at(i).second + 1) %= MOD;
      }
    }
  }
  // rep(i,n+1) cout << dp.at(i) << " ";
  // cout << endl;
  // cout << imos.at(n) << endl;
  cout << (acm + imos.at(n)) % MOD << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  long n, k;
  cin >> n >> k;
  vector<pll> data(k);
  rep(i, k) cin >> data.at(i).first >> data.at(i).second;
  vector<long> dp(500010, 0);
  vector<long> imos(500010, 0);
  dp.at(1) = 1;
  long acm = 0;
  REP(v, 1, n) {
    if (v == 1) {
      rep(i, k) {
        imos.at(v + data.at(i).first) += 1;
        imos.at(v + data.at(i).second + 1) -= 1;
      }
    } else {
      acm += imos.at(v);
      acm %= MOD;
      dp.at(v) = acm;
      rep(i, k) {
        imos.at(v + data.at(i).first) += acm;
        imos.at(v + data.at(i).first) % MOD;
        imos.at(v + data.at(i).second + 1) -= acm;
        imos.at(v + data.at(i).second + 1) += MOD;
        imos.at(v + data.at(i).second + 1) %= MOD;
      }
    }
  }
  // rep(i,n+1) cout << dp.at(i) << " ";
  // cout << endl;
  // cout << imos.at(n) << endl;
  cout << (acm + imos.at(n)) % MOD << endl;
}