結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー | aajisaka |
提出日時 | 2020-09-26 02:32:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 317 ms / 2,000 ms |
コード長 | 4,171 bytes |
コンパイル時間 | 2,045 ms |
コンパイル使用メモリ | 206,600 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-06-28 10:59:16 |
合計ジャッジ時間 | 13,276 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 273 ms
5,248 KB |
testcase_01 | AC | 267 ms
5,376 KB |
testcase_02 | AC | 272 ms
5,376 KB |
testcase_03 | AC | 273 ms
5,376 KB |
testcase_04 | AC | 274 ms
5,376 KB |
testcase_05 | AC | 273 ms
5,376 KB |
testcase_06 | AC | 269 ms
5,376 KB |
testcase_07 | AC | 271 ms
5,376 KB |
testcase_08 | AC | 275 ms
5,376 KB |
testcase_09 | AC | 275 ms
5,376 KB |
testcase_10 | AC | 276 ms
5,376 KB |
testcase_11 | AC | 279 ms
5,504 KB |
testcase_12 | AC | 279 ms
5,504 KB |
testcase_13 | AC | 275 ms
5,376 KB |
testcase_14 | AC | 286 ms
5,504 KB |
testcase_15 | AC | 317 ms
6,016 KB |
testcase_16 | AC | 314 ms
6,016 KB |
testcase_17 | AC | 312 ms
6,016 KB |
testcase_18 | AC | 311 ms
6,016 KB |
testcase_19 | AC | 313 ms
6,016 KB |
testcase_20 | AC | 313 ms
6,016 KB |
testcase_21 | AC | 313 ms
6,016 KB |
testcase_22 | AC | 310 ms
6,144 KB |
testcase_23 | AC | 313 ms
6,144 KB |
testcase_24 | AC | 315 ms
6,016 KB |
testcase_25 | AC | 316 ms
6,016 KB |
testcase_26 | AC | 314 ms
6,016 KB |
testcase_27 | AC | 272 ms
5,376 KB |
testcase_28 | AC | 270 ms
5,376 KB |
testcase_29 | AC | 298 ms
6,016 KB |
testcase_30 | AC | 285 ms
5,760 KB |
testcase_31 | AC | 285 ms
5,760 KB |
testcase_32 | AC | 291 ms
6,016 KB |
ソースコード
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; constexpr long double PI = 3.14159265358979323846264338327950288L; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // Fast Walsh-Hadamard transform // Original: https://kazuma8128.hatenablog.com/entry/2018/05/31/144519 // Get C[k] = Sum(A[i]*B[j]) (i^j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_xor(A); fwt_xor(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_xor(C); template <typename T> void fwt_xor(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { T x = f[j], y = f[j | i]; f[j] = x + y, f[j | i] = x - y; } } } } template <typename T> void ifwt_xor(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { T x = f[j], y = f[j | i]; f[j] = (x + y) / 2, f[j | i] = (x - y) / 2; } } } } // Get C[k] = Sum(A[i]*B[j]) (i|j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_or(A); fwt_or(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_or(C); template <typename T> void fwt_or(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j | i] += f[j]; } } } } template <typename T> void ifwt_or(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j | i] -= f[j]; } } } } // Get C[k] = Sum(A[i]*B[j]) (i&j=k) by O(nlogn) // n must be 2^p (p: non-negative integer) // fwt_and(A); fwt_and(B); // rep(i, n) C[i] = A[i]*B[i]; // ifwt_and(C); template <typename T> void fwt_and(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j] += f[j | i]; } } } } template <typename T> void ifwt_and(vector<T>& f) { int n = f.size(); for (int i = 1; i < n; i <<= 1) { for (int j = 0; j < n; j++) { if ((j & i) == 0) { f[j] -= f[j | i]; } } } } class No1240OrSumOfXorPair { public: void solve(istream& cin, ostream& cout) { SPEED; int n, x; cin >> n >> x; vector<int> a(n); rep(i, n) { cin >> a[i]; } ll ret = 0; vector<ll> A(1<<18); rep(i, n) { A[a[i]]++; } ll cnt = 0; fwt_xor(A); rep(i, 1<<18) { A[i] *= A[i]; } ifwt_xor(A); A[0] -= n; // i == j for(int i=0; i<x; i++) { cnt += A[i]/2; } debug(cnt); for(int k=0; k<18; k++) { int used = 0; rep(i, 1<<18) A[i] = 0; rep(i, n) { if ((a[i]&(1<<k)) == 0) { A[a[i]]++; used++; } } fwt_xor(A); rep(i, 1<<18) A[i] *= A[i]; ifwt_xor(A); ll cnt2 = 0; A[0] -= used; for(int i=0; i<x; i++) { cnt2 += A[i]/2; debug(k, i, A[i]); } ret += (cnt-cnt2)*(1LL<<k); } cout << ret << endl; } }; signed main() { No1240OrSumOfXorPair solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }