Problem p03096 (C++)

Buggy submission (status: Runtime Error):
// 高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 1000000007

// つねに10億7などの剰余をとる構造体
// 参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
// 参考:
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
  ll x;
  modint(ll x) : x(x % mod) {}
  modint &operator+=(const modint a) {
    (x += a.x) %= mod;
    return *this;
  }
  modint &operator-=(const modint a) {
    (x -= a.x) %= mod;
    if (x < 0)
      x += mod;
    return *this;
  }
  modint &operator*=(const modint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint &operator/=(modint a) {
    ll exp = mod - 2;
    while (exp > 0) {
      if (exp & 1)
        *this *= a.x;
      a *= a.x;
      exp >>= 1;
    }
    return *this;
  }
  modint operator+(const modint a) const {
    modint res(*this);
    return res += a;
  }
  modint operator-(const modint a) const {
    modint res(*this);
    return res -= a;
  }
  modint operator*(const modint a) const {
    modint res(*this);
    return res *= a;
  }
  modint operator/(const modint a) const {
    modint res(*this);
    return res /= a;
  }
};
modint modpow(modint x, ll n) {
  modint res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x.x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  modint ans = 1;
  int tmp;
  int n;
  cin >> n;
  vector<pair<int, ll>> lo(n + 1);
  REP(i, n + 1) lo[i] = make_pair(-1, (ll)0);
  int prec = 0, c;
  REP(i, n) {
    cin >> c;
    if (lo[c].first != i - 1 && lo[c].first != -1)
      ans += lo[c].second;
    lo[c] = make_pair(i, ans.x);
  }
  cout << ans.x << endl;
}

Fixed submission:
// 高知能系Vtuberの高井茅乃です。
// Twitter: https://twitter.com/takaichino
// YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INTINF 1999999999
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define MODA 1000000007

// つねに10億7などの剰余をとる構造体
// 参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
// 参考:
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod = MODA;
struct modint {
  ll x;
  modint(ll x) : x(x % mod) {}
  modint &operator+=(const modint a) {
    (x += a.x) %= mod;
    return *this;
  }
  modint &operator-=(const modint a) {
    (x -= a.x) %= mod;
    if (x < 0)
      x += mod;
    return *this;
  }
  modint &operator*=(const modint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint &operator/=(modint a) {
    ll exp = mod - 2;
    while (exp > 0) {
      if (exp & 1)
        *this *= a.x;
      a *= a.x;
      exp >>= 1;
    }
    return *this;
  }
  modint operator+(const modint a) const {
    modint res(*this);
    return res += a;
  }
  modint operator-(const modint a) const {
    modint res(*this);
    return res -= a;
  }
  modint operator*(const modint a) const {
    modint res(*this);
    return res *= a;
  }
  modint operator/(const modint a) const {
    modint res(*this);
    return res /= a;
  }
};
modint modpow(modint x, ll n) {
  modint res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x.x;
    x = x * x;
    n >>= 1;
  }
  return res;
}

int main() {
  modint ans = 1;
  int tmp;
  int n;
  cin >> n;
  vector<pair<int, ll>> lo(200001);
  REP(i, 200001) lo[i] = make_pair(-1, (ll)0);
  int prec = 0, c;
  REP(i, n) {
    cin >> c;
    if (lo[c].first != i - 1 && lo[c].first != -1)
      ans += lo[c].second;
    lo[c] = make_pair(i, ans.x);
  }
  cout << ans.x << endl;
}