結果

問題 No.1240 Or Sum of Xor Pair
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-09-25 21:46:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,255 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 101,396 KB
実行使用メモリ 20,312 KB
最終ジャッジ日時 2023-09-10 15:09:09
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
19,664 KB
testcase_01 AC 45 ms
19,340 KB
testcase_02 AC 44 ms
19,416 KB
testcase_03 AC 45 ms
19,464 KB
testcase_04 AC 45 ms
19,404 KB
testcase_05 AC 45 ms
19,364 KB
testcase_06 AC 44 ms
19,488 KB
testcase_07 AC 45 ms
19,656 KB
testcase_08 AC 47 ms
19,452 KB
testcase_09 AC 45 ms
19,404 KB
testcase_10 AC 47 ms
19,360 KB
testcase_11 AC 48 ms
19,388 KB
testcase_12 AC 49 ms
19,768 KB
testcase_13 AC 50 ms
19,688 KB
testcase_14 AC 50 ms
19,604 KB
testcase_15 AC 69 ms
20,180 KB
testcase_16 AC 70 ms
20,216 KB
testcase_17 AC 69 ms
20,204 KB
testcase_18 AC 69 ms
20,260 KB
testcase_19 AC 70 ms
20,272 KB
testcase_20 AC 70 ms
20,180 KB
testcase_21 AC 69 ms
20,300 KB
testcase_22 AC 70 ms
20,184 KB
testcase_23 AC 71 ms
20,208 KB
testcase_24 AC 72 ms
20,132 KB
testcase_25 AC 70 ms
20,240 KB
testcase_26 AC 70 ms
20,312 KB
testcase_27 AC 44 ms
19,396 KB
testcase_28 AC 44 ms
19,472 KB
testcase_29 AC 68 ms
20,132 KB
testcase_30 AC 55 ms
20,000 KB
testcase_31 AC 56 ms
20,000 KB
testcase_32 AC 66 ms
20,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }

constexpr int E = 18;

void hadamard(vector<__int128_t> &fs) {
  for (int e = 0; e < E; ++e) {
    for (int h = 0; h < 1 << E; ++h) {
      if (!(h & 1 << e)) {
        const __int128_t tmp = fs[h] - fs[h | 1 << e];
        fs[h] += fs[h | 1 << e];
        fs[h | 1 << e] = tmp;
      }
    }
  }
}

int N, X;
vector<int> A;

int main() {
  for (; ~scanf("%d%d", &N, &X); ) {
    A.resize(N);
// if(N==200'000){A.assign(N,(1<<E)-1);}else
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    
    vector<__int128_t> fs0(1 << E), fs1(1 << E);
    for (int i = 0; i < N; ++i) {
      fs0[A[i]] += 1;
      fs1[A[i]] += A[i];
    }
    hadamard(fs0);
    hadamard(fs1);
    vector<__int128_t> gs0(1 << E), gs1(1 << E);
    for (int h = 0; h < 1 << E; ++h) {
      gs0[h] = fs0[h] * fs0[h];
      gs1[h] = fs0[h] * fs1[h];
    }
    hadamard(gs0);
    hadamard(gs1);
    for (int h = 0; h < 1 << E; ++h) {
      gs0[h] >>= E;
      gs1[h] >>= E;
    }
    
    __int128_t ans = 0;
    // or = (xor + sum) / 2
    for (int h = 0; h < 1 << E; ++h) {
      if (h < X) {
        ans += gs0[h] * h;
        ans += gs1[h] * 2;
      }
    }
    ans /= 2;
    
    for (int i = 0; i < N; ++i) {
      if ((A[i] ^ A[i]) < X) {
        ans -= (A[i] | A[i]);
      }
    }
    ans /= 2;
    printf("%lld\n", (Int)ans);
  }
  return 0;
}
0