結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー | aajisaka |
提出日時 | 2020-09-26 02:10:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,124 bytes |
コンパイル時間 | 2,583 ms |
コンパイル使用メモリ | 205,336 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-06-28 10:31:21 |
合計ジャッジ時間 | 13,470 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 284 ms
9,344 KB |
testcase_01 | AC | 285 ms
9,344 KB |
testcase_02 | AC | 281 ms
9,344 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 283 ms
9,472 KB |
testcase_28 | AC | 280 ms
9,344 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 300 ms
9,344 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<ll> a(1<<18); rep(i, n) { int ai; cin >> ai; a[ai]++; } ll ret = 0; vector<ll> A(1<<18); auto B = A; ll cnt = 0; A = a; fwt_xor(A); rep(i, 1<<18) { B[i] = A[i]*A[i]; } ifwt_xor(B); for(int i=1; i<x; i++) { cnt += B[i]/2; } debug(cnt); for(int k=0; k<18; k++) { rep(i, 1LL<<18) { if ((i & (1LL << k)) == 0) { A[i] = a[i]; } else { A[i] = 0; } } fwt_xor(A); rep(i, 1<<18) B[i] = A[i]*A[i]; ifwt_xor(B); ll cnt2 = 0; for(int i=1; i<x; i++) { cnt2 += B[i]/2; //debug(k, i, B[i]/2); } 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; }