Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

// ------------------------------------------------------------------------------------------

int N, K;
vec<int> A, bin;

signed main() {
  cin >> N >> K;
  A.resize(N), bin.resize(50);
  rep (i, N) {
    cin >> A[i];
  }

  rep (digit, 46) {
    int mask = 1LL << digit;
    rep (i, N) {
      if (A[i] & mask) { bin[digit]++; }
    }
  }

  map<int, int> mp1;
  int Max = 0;
  for (int mask = 0; mask < (1LL<<22); mask++) {
    if (mask > K) continue;

    int num = 0;
    for (int digit = 0; digit < 45; digit++) {
      if ((mask >> digit) & 1) {
        num += (1LL << digit) * (N - bin[digit]);
      } else {
        num += (1LL << digit) * bin[digit];
      }
    }
    chmax(Max, num);
    // mp1[mask] = Max;
    mp1.emplace({mask, Max});
  }

  int ans = 0;
  chmax(ans, Max);
  for (int mask = 1; mask <= (1LL<<22); mask++) {
    mask = mask << 22;
    if (mask > K) continue;
    int num = 0;
    for (int digit = 0; digit < 45; digit++) {
      if ((mask >> digit) & 1) {
        num += (1LL << digit) * (N - bin[digit]);
      } else {
        num += (1LL << digit) * bin[digit];
      }
    }

    int hoge = K - mask;
    // if (mp1.count(hoge)) {
      chmax(ans, num + mp1[hoge]);
    // }
  }

  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:85:16: error: no matching function for call to 'std::map<long long int, long long int>::emplace(<brace-enclosed initializer list>)'
   85 |     mp1.emplace({mask, Max});
      |     ~~~~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:588:9: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Val>, std::_Select1st<std::pair<const _Key, _Val> >, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::emplace(_Args&& ...) [with _Args = {}; _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; typename std::_Rb_tree<_Key, std::pair<const _Key, _Val>, std::_Select1st<std::pair<const _Key, _Val> >, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val> >::other>::iterator = std::_Rb_tree<long long int, std::pair<const long long int, long long int>, std::_Select1st<std::pair<const long long int, long long int> >, std::less<long long int>, std::allocator<std::pair<const long long int, long long int> > >::iterator; typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val> >::other = std::allocator<std::pair<const long long int, long long int> >; typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<std::pair<const _Key, _Val> > = __gnu_cxx::__alloc_traits<std::allocator<std::pair<const long long int, long long int> >, std::pair<const long long int, long long int> >::rebind<std::pair<const long long int, long long int> >; typename _Allocator::value_type = std::pair<const long long int, long long int>]'
  588 |         emplace(_Args&&... __args)
      |         ^~~~~~~
/usr/include/c++/14/bits/stl_map.h:588:9: note:   candidate expects 0 arguments, 1 provided