結果

問題 No.1240 Or Sum of Xor Pair
ユーザー pockynypockyny
提出日時 2023-04-26 11:01:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 83,884 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-27 15:50:50
合計ジャッジ時間 15,183 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 331 ms
7,296 KB
testcase_01 AC 341 ms
7,296 KB
testcase_02 AC 347 ms
7,296 KB
testcase_03 AC 339 ms
7,424 KB
testcase_04 AC 338 ms
7,424 KB
testcase_05 AC 336 ms
7,424 KB
testcase_06 AC 350 ms
7,424 KB
testcase_07 AC 343 ms
7,296 KB
testcase_08 AC 345 ms
7,296 KB
testcase_09 AC 345 ms
7,424 KB
testcase_10 AC 347 ms
7,552 KB
testcase_11 AC 350 ms
7,552 KB
testcase_12 AC 353 ms
7,808 KB
testcase_13 AC 354 ms
7,552 KB
testcase_14 AC 351 ms
7,808 KB
testcase_15 AC 382 ms
8,960 KB
testcase_16 AC 380 ms
8,960 KB
testcase_17 AC 377 ms
8,960 KB
testcase_18 AC 380 ms
8,960 KB
testcase_19 AC 392 ms
8,960 KB
testcase_20 AC 403 ms
8,960 KB
testcase_21 AC 381 ms
8,960 KB
testcase_22 AC 403 ms
8,960 KB
testcase_23 AC 389 ms
8,960 KB
testcase_24 AC 387 ms
8,960 KB
testcase_25 AC 379 ms
8,960 KB
testcase_26 AC 378 ms
8,832 KB
testcase_27 AC 349 ms
7,296 KB
testcase_28 AC 341 ms
7,296 KB
testcase_29 AC 369 ms
9,088 KB
testcase_30 AC 351 ms
8,064 KB
testcase_31 AC 344 ms
8,064 KB
testcase_32 AC 361 ms
8,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
void fwt(vector<ll>& f) {
    int n = f.size();
    for (int i = 1; i < n; i <<= 1) {
        for (int j = 0; j < n; j++) {
            if ((j & i) == 0) {
                ll x = f[j], y = f[j | i];
                f[j] = x + y, f[j | i] = x - y;
            }
        }
    }
}

void ifwt(vector<ll>& f) {
    int n = f.size();
    for (int i = 1; i < n; i <<= 1) {
        for (int j = 0; j < n; j++) {
            if ((j & i) == 0) {
                ll x = f[j], y = f[j | i];
                f[j] = (x + y) / 2, f[j | i] = (x - y) / 2;
            }
        }
    }
}

vector<ll> cnt1(1<<18),cnt2(1<<18);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,k,n,x; cin >> n >> x;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin >> a[i];
    ll ans = 0;
    for(j=0;j<18;j++){
        for(i=0;i<(1<<18);i++) cnt1[i] = cnt2[i] = 0;
        for(i=0;i<n;i++){
            if(!((a[i]>>j)&1)) cnt1[a[i]]++;
            cnt2[a[i]]++;
        }
        fwt(cnt1); fwt(cnt2);
        for(i=0;i<(1<<18);i++){
            cnt1[i] *= cnt1[i];
            cnt2[i] *= cnt2[i];
        }
        ifwt(cnt1); ifwt(cnt2);
        ll sum1 = 0,sum2 = 0;
        for(i=0;i<x;i++){
            sum1 += cnt1[i]; sum2 += cnt2[i];
        }
        ans += (sum2 - sum1)*(1LL<<j);
    }
    for(i=0;i<n;i++) ans -= a[i];
    ans /= 2;
    cout << ans << "\n";
}
0