Problem p02975 (C++)

Buggy submission (status: Runtime Error):
// sjq
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;

typedef long long LL;

const int N = 80000;

int n;
LL a[N + 5];
int C[N + 5];
vector<LL> V;

int main() {
  //	freopen("circle.in", "r", stdin);
  //	freopen("circle.out", "w", stdout);

  int T;
  // scanf("%d", &T);
  T = 1;
  while (T--) {
    V.clear();
    C[0] = 0;

    scanf("%d", &n);
    for (register int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      C[i] = 0;
    }

    bool p = 1;
    for (register int i = 1; i <= n; i++) {
      int f = -1;
      for (register int j = V.size() - 1; j >= 0; j--)
        if (V[j] == a[i])
          f = j;
      if (!~f) {
        V.push_back(a[i]);
        C[V.size() - 1] = 1;
        if (V.size() > 3) {
          p = 0;
          break;
        }
      } else
        C[f]++;
    }
    if (!p) {
      printf("No\n");
      continue;
    }
    if (V.size() == 1) {
      if (V[0] == 0)
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }
    if (n % 3) {
      if (V.size() == 1 && V[0] == 0)
        printf("Yes\n");
      printf("No\n");
      continue;
    }

    if (V.size() > 3) {
      printf("No\n");
      continue;
    }

    if (V.size() == 2) {
      if (V[0] == 0 && C[0] == n / 3)
        printf("Yes\n");
      else if (V[1] == 0 && C[1] == n / 3)
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }

    if (V.size() == 3) {
      if (V[0] ^ V[1] ^ V[2])
        printf("No\n");
      else if (C[0] == C[1] && C[1] == C[2])
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }
  }
  return 0;
}


Fixed submission:
// sjq
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;

typedef long long LL;

const int N = 100000;

int n;
LL a[N + 5];
int C[N + 5];
vector<LL> V;

int main() {
  //	freopen("circle.in", "r", stdin);
  //	freopen("circle.out", "w", stdout);

  int T;
  // scanf("%d", &T);
  T = 1;
  while (T--) {
    V.clear();
    C[0] = 0;

    scanf("%d", &n);
    for (register int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      C[i] = 0;
    }

    bool p = 1;
    for (register int i = 1; i <= n; i++) {
      int f = -1;
      for (register int j = V.size() - 1; j >= 0; j--)
        if (V[j] == a[i])
          f = j;
      if (!~f) {
        V.push_back(a[i]);
        C[V.size() - 1] = 1;
        if (V.size() > 3) {
          p = 0;
          break;
        }
      } else
        C[f]++;
    }
    if (!p) {
      printf("No\n");
      continue;
    }
    if (V.size() == 1) {
      if (V[0] == 0)
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }
    if (n % 3) {
      if (V.size() == 1 && V[0] == 0)
        printf("Yes\n");
      printf("No\n");
      continue;
    }

    if (V.size() > 3) {
      printf("No\n");
      continue;
    }

    if (V.size() == 2) {
      if (V[0] == 0 && C[0] == n / 3)
        printf("Yes\n");
      else if (V[1] == 0 && C[1] == n / 3)
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }

    if (V.size() == 3) {
      if (V[0] ^ V[1] ^ V[2])
        printf("No\n");
      else if (C[0] == C[1] && C[1] == C[2])
        printf("Yes\n");
      else
        printf("No\n");
      continue;
    }
  }
  return 0;
}