Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#if 1
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type, name, N)                                                 \
  std::vector<type> name(N);                                                   \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name[nnn];                                                          \
  }

#define LOADVEC2(type, name0, name1, N)                                        \
  std::vector<type> name0(N), name1(N);                                        \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
  }

#define LOAD(type, name)                                                       \
  type name;                                                                   \
  cin >> name;

signed main() {
  ios::sync_with_stdio(false);
  LOAD(int, N);
  LOADVEC(int, C0, N);
  std::vector<int> C;
  C.reserve(N);
  int last = -1;
  for (int i = 0; i < N; ++i) {
    if (last != C0[i])
      C.push_back(C0[i]);
    last = C0[i];
  }
  std::vector<int> res(C.size());
  std::vector<int> lastColor(N, -1);
  int lastColor2 = -1;
  res[0] = 1;
  lastColor[C[0]] = 0;
  for (int i = 1; i < C.size(); ++i) {
    if (lastColor[C[i]] == -1) {
      res[i] = res[i - 1];
    } else {
      res[i] = res[i - 1] + res[lastColor[C[i]]];
      res[i] %= MOD;
    }
    lastColor[C[i]] = i;
  }
  cout << res.back();
  return 0;
}
#endif


Fixed submission:
#if 1
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define int long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810;

#define LOADVEC(type, name, N)                                                 \
  std::vector<type> name(N);                                                   \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name[nnn];                                                          \
  }

#define LOADVEC2(type, name0, name1, N)                                        \
  std::vector<type> name0(N), name1(N);                                        \
  for (int nnn = 0; nnn < N; ++nnn) {                                          \
    cin >> name0[nnn];                                                         \
    cin >> name1[nnn];                                                         \
  }

#define LOAD(type, name)                                                       \
  type name;                                                                   \
  cin >> name;

signed main() {
  ios::sync_with_stdio(false);
  LOAD(int, N);
  LOADVEC(int, C0, N);
  std::vector<int> C;
  C.reserve(N);
  int last = -1;
  for (int i = 0; i < N; ++i) {
    if (last != C0[i])
      C.push_back(C0[i]);
    last = C0[i];
  }
  std::vector<int> res(C.size());
  std::vector<int> lastColor(300000, -1);
  int lastColor2 = -1;
  res[0] = 1;
  lastColor[C[0]] = 0;
  for (int i = 1; i < C.size(); ++i) {
    if (lastColor[C[i]] == -1) {
      res[i] = res[i - 1];
    } else {
      res[i] = res[i - 1] + res[lastColor[C[i]]];
      res[i] %= MOD;
    }
    lastColor[C[i]] = i;
  }
  cout << res.back();
  return 0;
}
#endif