結果

問題 No.1240 Or Sum of Xor Pair
ユーザー MisterMister
提出日時 2020-09-26 13:45:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 77,068 KB
実行使用メモリ 6,024 KB
最終ジャッジ日時 2023-09-11 10:15:45
合計ジャッジ時間 11,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
5,592 KB
testcase_01 AC 240 ms
5,404 KB
testcase_02 AC 241 ms
5,432 KB
testcase_03 AC 245 ms
5,612 KB
testcase_04 AC 242 ms
5,576 KB
testcase_05 AC 242 ms
5,484 KB
testcase_06 AC 243 ms
5,444 KB
testcase_07 AC 242 ms
5,436 KB
testcase_08 AC 243 ms
5,556 KB
testcase_09 AC 242 ms
5,428 KB
testcase_10 AC 245 ms
5,800 KB
testcase_11 AC 246 ms
5,504 KB
testcase_12 AC 249 ms
5,560 KB
testcase_13 AC 250 ms
5,440 KB
testcase_14 AC 250 ms
5,544 KB
testcase_15 AC 282 ms
5,908 KB
testcase_16 AC 280 ms
5,988 KB
testcase_17 AC 279 ms
5,964 KB
testcase_18 AC 279 ms
5,888 KB
testcase_19 AC 281 ms
6,024 KB
testcase_20 AC 281 ms
5,872 KB
testcase_21 AC 279 ms
5,928 KB
testcase_22 AC 280 ms
5,900 KB
testcase_23 AC 280 ms
5,936 KB
testcase_24 AC 281 ms
5,900 KB
testcase_25 AC 282 ms
5,904 KB
testcase_26 AC 283 ms
5,944 KB
testcase_27 AC 239 ms
5,696 KB
testcase_28 AC 240 ms
5,472 KB
testcase_29 AC 264 ms
6,008 KB
testcase_30 AC 252 ms
5,564 KB
testcase_31 AC 251 ms
5,568 KB
testcase_32 AC 262 ms
5,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0