結果
| 問題 | No.1240 Or Sum of Xor Pair |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-25 21:46:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 2,255 bytes |
| 記録 | |
| コンパイル時間 | 990 ms |
| コンパイル使用メモリ | 105,436 KB |
| 実行使用メモリ | 20,636 KB |
| 最終ジャッジ日時 | 2024-06-28 06:19:44 |
| 合計ジャッジ時間 | 5,280 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#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;
}