Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cout.tie(0);                                                                 \
  cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

int main() {
  IOS

      ll n;
  cin >> n;
  vector<ll> c(n);
  for (ll i = 0; i < n; ++i) {
    cin >> c[i];
  }
  vector<ll> no_rep;
  for (ll i = 0; i < n; ++i) {
    ll ind = i;
    no_rep.push_back(c[i]);
    while (ind < n && c[i] == c[ind]) {
      ++ind;
    }
    --ind;
    i = ind;
  }

  vector<ll> last(n + 100, -1);
  vector<ll> prev(202020 + 10, -1);
  for (ll i = 0; i < no_rep.size(); ++i) {
    prev[i] = last[no_rep[i]];
    last[no_rep[i]] = i;
  }

  vector<ll> dp(n + 200, 0);
  dp[0] = 1;
  for (ll i = 1; i < no_rep.size(); ++i) {
    if (prev[i] == -1) {
      dp[i] = dp[i - 1];
      dp[i] %= MOD;
    } else {
      dp[i] = dp[i - 1] + dp[prev[i]];
      dp[i] %= MOD;
    }
  }
  cout << dp[no_rep.size() - 1];

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
vector<long long> factors;
#define ll long long

#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cout.tie(0);                                                                 \
  cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

int main() {
  IOS

      ll n;
  cin >> n;
  vector<ll> c(n);
  for (ll i = 0; i < n; ++i) {
    cin >> c[i];
  }
  vector<ll> no_rep;
  for (ll i = 0; i < n; ++i) {
    ll ind = i;
    no_rep.push_back(c[i]);
    while (ind < n && c[i] == c[ind]) {
      ++ind;
    }
    --ind;
    i = ind;
  }

  vector<ll> last(202020 + 100, -1);
  vector<ll> prev(202020 + 10, -1);
  for (ll i = 0; i < no_rep.size(); ++i) {
    prev[i] = last[no_rep[i]];
    last[no_rep[i]] = i;
  }

  vector<ll> dp(n + 200, 0);
  dp[0] = 1;
  for (ll i = 1; i < no_rep.size(); ++i) {
    if (prev[i] == -1) {
      dp[i] = dp[i - 1];
      dp[i] %= MOD;
    } else {
      dp[i] = dp[i - 1] + dp[prev[i]];
      dp[i] %= MOD;
    }
  }
  cout << dp[no_rep.size() - 1];

  return 0;
}