Problem p02975 (C++)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A;

map<ll, ll> A_map;

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  A.resize(N);
  REP(i, N) {
    cin >> A[i];
    A_map[A[i]]++;
  }

  if (A_map.size() == 3) {
    vector<ll> val(3);
    ll j = 0;
    for (auto &a_tmp : A_map) {
      if (a_tmp.second != N / 3) {
        printf("No\n");
        return 0;
      }
      val[j] = a_tmp.first;
      j++;
    }

    if (val[0] == (val[1] ^ val[2]) && val[1] == (val[0] ^ val[2]) &&
        val[2] == (val[1] ^ val[0])) {
      printf("Yes\n");
      return 0;
    }
  } else if (A_map.size() == 2) {
    assert(false);
  } else if (A_map.size() == 1) {
    for (auto &a_tmp : A_map) {
      if (a_tmp.first != 0) {
        printf("No\n");
      } else {
        printf("Yes\n");
      }
      return 0;
    }
  }
  printf("No\n");

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A;

map<ll, ll> A_map;

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  A.resize(N);
  REP(i, N) {
    cin >> A[i];
    A_map[A[i]]++;
  }

  if (A_map.size() == 3) {
    vector<ll> val(3);
    ll j = 0;
    for (auto &a_tmp : A_map) {
      if (a_tmp.second != N / 3) {
        printf("No\n");
        return 0;
      }
      val[j] = a_tmp.first;
      j++;
    }

    if (val[0] == (val[1] ^ val[2]) && val[1] == (val[0] ^ val[2]) &&
        val[2] == (val[1] ^ val[0])) {
      printf("Yes\n");
      return 0;
    }
  } else if (A_map.size() == 2) {
    vector<ll> val(2);
    for (auto &a_tmp : A_map) {
      if (a_tmp.first == 0) {
        val[0] = a_tmp.second;
      } else {
        val[1] = a_tmp.second;
      }
    }
    if (val[1] == (N / 3) * 2 && val[0] == N / 3) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
    return 0;
  } else if (A_map.size() == 1) {
    for (auto &a_tmp : A_map) {
      if (a_tmp.first != 0) {
        printf("No\n");
      } else {
        printf("Yes\n");
      }
      return 0;
    }
  }
  printf("No\n");

  return 0;
}