Language: C++

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	uint64_t N, K, a;
	vector<uint64_t> A;
	uint64_t x = 0;
	uint64_t ans = 0;
	uint32_t o = 1;
	vector<uint64_t> num1(64, 0);

	cin >> N >> K;

	// 読み込んだ数値の各桁ごとの1の数を取得する
	for (int i = 0; i < N; i++)
	{
		cin >> a;
		A.push_back(a);
		uint32_t idx = 0;
		while (a)
		{
			if (a & 1)
			{
				num1[idx]++;
			}
			a = a >> 1;
			idx++;
		}
	}
	// Kの2進数での桁数を調査
	uint64_t tmpK = K;
	while (tmpK)
	{
		tmpK = tmpK >> 1;
		o++;
	}

	// Kの上位桁数から計算結果をあてはめる
	for (int i = o - 1; i >= 0; i--)
	{
		// 1の数がNの半分より少ないときは最大値を取る値の当該ビットは1となる
		if (num1[i] <= N / 2)
		{
			if (K >= x + (1i64 << i))
			{
				x = x + (1i64 << i);
			}
		}
	}
	// 最大値を求める
	for (auto itr = A.begin(); itr != A.end(); itr++)
	{
		ans = ans + (x ^ *itr);
	}

    cout << ans << endl; 

	return(0);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'uint64_t' was not declared in this scope
    7 |         uint64_t N, K, a;
      |         ^~~~~~~~
a.cc:3:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <vector>
  +++ |+#include <cstdint>
    3 | using namespace std;
a.cc:8:24: error: template argument 2 is invalid
    8 |         vector<uint64_t> A;
      |                        ^
a.cc:9:17: error: expected ';' before 'x'
    9 |         uint64_t x = 0;
      |                 ^~
      |                 ;
a.cc:10:17: error: expected ';' before 'ans'
   10 |         uint64_t ans = 0;
      |                 ^~~~
      |                 ;
a.cc:11:9: error: 'uint32_t' was not declared in this scope
   11 |         uint32_t o = 1;
      |         ^~~~~~~~
a.cc:11:9: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:12:24: error: template argument 2 is invalid
   12 |         vector<uint64_t> num1(64, 0);
      |                        ^
a.cc:12:36: error: expression list treated as compound expression in initializer [-fpermissive]
   12 |         vector<uint64_t> num1(64, 0);
      |                                    ^
a.cc:14:16: error: 'N' was not declared in this scope
   14 |         cin >> N >> K;
      |                ^
a.cc:14:21: error: 'K' was not declared in this scope
   14 |         cin >> N >> K;
      |                     ^
a.cc:19:24: error: 'a' was not declared in this scope
   19 |                 cin >> a;
      |                        ^
a.cc:20:19: error: request for member 'push_back' in 'A', which is of non-class type 'int'
   20 |                 A.push_back(a);
      |                   ^~~~~~~~~
a.cc:21:25: error: expected ';' before 'idx'
   21 |                 uint32_t idx = 0;
      |                         ^~~~
      |                         ;
a.cc:26:38: error: 'idx' was not declared in this scope
   26 |                                 num1[idx]++;
      |                                      ^~~
a.cc:29:25: error: 'idx' was not declared in this scope
   29 |                         idx++;
      |                         ^~~
a.cc:33:17: error: expected ';' before 'tmpK'
   33 |         uint64_t tmpK = K;
      |                 ^~~~~
      |                 ;
a.cc:34:16: error: 'tmpK' was not declared in this scope; did you mean 'tm'?
   34 |         while (tmpK)
      |                ^~~~
      |                tm
a.cc:37:17: error: 'o' was not declared in this scope
   37 |                 o++;
      |                 ^
a.cc:41:22: error: 'o' was not declared in this scope
   41 |         for (int i = o - 1; i >= 0; i--)
      |                      ^
a.cc:44:25: error: invalid types 'int[int]' for array subscript
   44 |                 if (num1[i] <= N / 2)
      |                         ^
a.cc:46:34: error: 'x' was not declared in this scope
   46 |                         if (K >= x + (1i64 << i))
      |                                  ^
a.cc:46:39: error: unable to find numeric literal operator 'operator""i64'
   46 |                         if (K >= x + (1i64 << i))
      |                                       ^~~~
a.cc:48:42: error: unable to find numeric literal operator 'operator""i64'
   48 |                                 x = x + (1i64 << i);
      |                                          ^~~~
a.cc:53:27: error: request for member 'begin' in 'A', which is of non-class type 'int'
   53 |         for (auto itr = A.begin(); itr != A.end(); itr++)
      |                           ^~~~~
a.cc:53:45: error: request for member 'end' in 'A', which is of non-class type 'int'
   53 |         for (auto itr = A.begin(); itr != A.end(); itr++)
      |                                             ^~~
a.cc:55:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |                 ans = ans + (x ^ *itr);
      |                 ^~~
      |                 abs
a.cc:55:30: error: 'x' was not declared in this scope
   55 |                 ans = ans + (x ^ *itr);
      |                              ^
a.cc:58:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   58 |     cout << ans << endl;
      |             ^~~
      |             abs