結果
問題 |
No.1240 Or Sum of Xor Pair
|
ユーザー |
![]() |
提出日時 | 2020-10-02 20:30:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 428 ms / 2,000 ms |
コード長 | 2,157 bytes |
コンパイル時間 | 2,062 ms |
コンパイル使用メモリ | 202,336 KB |
最終ジャッジ日時 | 2025-01-14 23:58:48 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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; }