結果
問題 | No.1240 Or Sum of Xor Pair |
ユーザー |
|
提出日時 | 2020-09-26 13:45:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 298 ms / 2,000 ms |
コード長 | 1,834 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 76,132 KB |
最終ジャッジ日時 | 2025-01-14 22:16:54 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream> #include <numeric> #include <vector> using lint = long long; constexpr int K = 18; void xor_convolution(std::vector<lint>& xs) { for (int i = 1; i < (1 << K); i <<= 1) { for (int b = 0; b < (1 << K); ++b) { if (b & i) continue; auto l = xs[b], r = xs[b | i]; xs[b] = l + r; xs[b | i] = l - r; } } for (auto& x : xs) x *= x; for (int i = 1; i < (1 << K); i <<= 1) { for (int b = 0; b < (1 << K); ++b) { if (b & i) continue; auto l = xs[b], r = xs[b | i]; xs[b] = l + r; xs[b | i] = l - r; } } for (auto& x : xs) x >>= K; } void solve() { int n, a; std::cin >> n >> a; std::vector<int> xs(n); for (auto& x : xs) std::cin >> x; lint tot; { int sz = 0; std::vector<lint> cnt(1 << K, 0); for (auto x : xs) { ++cnt[x]; ++sz; } xor_convolution(cnt); cnt[0] -= sz; for (auto& c : cnt) c >>= 1; tot = std::accumulate(cnt.begin(), cnt.begin() + a, 0LL); } lint ans = 0; for (int k = 1; k < (1 << K); k <<= 1) { lint num = tot; { int sz = 0; std::vector<lint> cnt(1 << K, 0); for (auto x : xs) { if (x & k) continue; ++cnt[x]; ++sz; } xor_convolution(cnt); cnt[0] -= sz; for (auto& c : cnt) c >>= 1; num -= std::accumulate(cnt.begin(), cnt.begin() + a, 0LL); } ans += k * num; } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }