Problem p02631 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

// マクロ定義
#define vvint(vec, n, m, l)                                                    \\
  vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化
#define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l));
#define vint vector<int>
#define pint pair<int, int>
#define rep(i, a) for (ll i = 0; i < (a); i++)
#define all(x) (x).begin(), (x).end()
#define debug system("pause") // デバッグ用
#define ret return 0

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) // 15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<vector<ll>> k(n, vector<ll>(100, 0));
  vector<ll> kk(100);
  rep(i, n) {
    cin >> a[i];
    ll tmp = a[i];
    ll j = 0;
    while (tmp) {
      k[i][j] = (tmp % 2);
      tmp /= 2;
      kk[j] += k[i][j];
      j++;
    }
  }

  for (ll i = 0; i < n; i++) {
    ll ans = 0;
    for (int j = 99; j >= 0; j--) {
      if (kk[j] % 2) {
        if (k[i][j] == 1) {
          ans += 0LL << j;
        } else {
          ans += 1LL << j;
        }
      } else {
        if (k[i][j] == 1) {
          ans += 1LL << j;
        } else {
          ans += 0LL << j;
        }
      }
    }
    if (i != n - 1)
      cout << ans << " ";
    else
      cout << ans << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

// マクロ定義
#define vvint(vec, n, m, l)                                                    \\
  vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化
#define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l));
#define vint vector<int>
#define pint pair<int, int>
#define rep(i, a) for (ll i = 0; i < (a); i++)
#define all(x) (x).begin(), (x).end()
#define debug system("pause") // デバッグ用
#define ret return 0

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) // 15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<vector<ll>> k(n, vector<ll>(0));
  vector<ll> kk(100);
  rep(i, n) {
    cin >> a[i];
    ll tmp = a[i];
    ll j = 0;
    while (tmp) {
      k[i].push_back(tmp % 2);
      tmp /= 2;
      kk[j] += k[i][j];
      j++;
    }
  }

  for (ll i = 0; i < n; i++) {
    ll ans = 0;
    for (int j = 100; j >= 0; j--) {
      if (kk[j] % 2) {
        if (k[i][j] == 1) {
          ans += 0LL << j;
        } else {
          ans += 1LL << j;
        }
      } else {
        if (k[i][j] == 1) {
          ans += 1LL << j;
        } else {
          ans += 0LL << j;
        }
      }
    }
    if (i != n - 1)
      cout << ans << " ";
    else
      cout << ans << endl;
  }

  return 0;
}