結果

問題 No.1240 Or Sum of Xor Pair
ユーザー 👑 emthrmemthrm
提出日時 2020-10-02 20:30:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 2,157 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 206,820 KB
実行使用メモリ 12,140 KB
最終ジャッジ日時 2023-09-23 02:57:43
合計ジャッジ時間 17,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 380 ms
11,224 KB
testcase_01 AC 380 ms
11,300 KB
testcase_02 AC 382 ms
11,360 KB
testcase_03 AC 388 ms
11,468 KB
testcase_04 AC 384 ms
11,224 KB
testcase_05 AC 381 ms
11,376 KB
testcase_06 AC 383 ms
11,352 KB
testcase_07 AC 382 ms
11,316 KB
testcase_08 AC 382 ms
11,340 KB
testcase_09 AC 384 ms
11,228 KB
testcase_10 AC 387 ms
11,312 KB
testcase_11 AC 389 ms
11,536 KB
testcase_12 AC 390 ms
11,536 KB
testcase_13 AC 387 ms
11,408 KB
testcase_14 AC 389 ms
11,424 KB
testcase_15 AC 422 ms
12,008 KB
testcase_16 AC 419 ms
12,000 KB
testcase_17 AC 422 ms
12,104 KB
testcase_18 AC 419 ms
12,096 KB
testcase_19 AC 421 ms
12,016 KB
testcase_20 AC 422 ms
12,116 KB
testcase_21 AC 423 ms
12,064 KB
testcase_22 AC 421 ms
12,140 KB
testcase_23 AC 422 ms
12,064 KB
testcase_24 AC 424 ms
12,092 KB
testcase_25 AC 425 ms
12,140 KB
testcase_26 AC 422 ms
12,012 KB
testcase_27 AC 382 ms
11,272 KB
testcase_28 AC 381 ms
11,320 KB
testcase_29 AC 405 ms
12,060 KB
testcase_30 AC 393 ms
11,752 KB
testcase_31 AC 392 ms
11,880 KB
testcase_32 AC 405 ms
12,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
std::vector<T> convolution_xor(const std::vector<T> &a, const std::vector<T> &b, const T UNITY = 0) {
  auto fwht = [&](std::vector<T> v) -> std::vector<T> {
    int n = v.size(), p = 1;
    while ((1 << p) < n) ++p;
    n = 1 << p;
    v.resize(n, UNITY);
    for (int i = 1; i < n; i <<= 1) for (int j = 0; j < n; ++j) {
      if ((j & i) == 0) {
        T tmp1 = v[j], tmp2 = v[j | i];
        v[j] = tmp1 + tmp2;
        v[j | i] = tmp1 - tmp2;
      }
    }
    return v;
  };
  std::vector<T> a_fwht = fwht(a), b_fwht = fwht(b);
  int n = a_fwht.size();
  for (int i = 0; i < n; ++i) a_fwht[i] *= b_fwht[i];
  std::vector<T> res = fwht(a_fwht);
  for (int i = 0; i < n; ++i) res[i] /= n;
  return res;
}

int main() {
  int n, x; cin >> n >> x;
  vector<int> a(n); REP(i, n) cin >> a[i];
  constexpr int B = 18, X = 1 << B;
  vector<ll> b(X, 0);
  REP(i, n) ++b[a[i]];
  b = convolution_xor(b, b);
  ll pat = -n;
  REP(i, x) pat += b[i];
  pat /= 2;
  ll ans = 0;
  REP(bit, B) {
    b.assign(X, 0);
    ll sum = 0;
    REP(i, n) {
      if (a[i] >> bit & 1) continue;
      ++b[a[i]];
      --sum;
    }
    b = convolution_xor(b, b);
    REP(i, x) sum += b[i];
    sum /= 2;
    ans += (pat - sum) * (1 << bit);
  }
  cout << ans << '\n';
  return 0;
}
0