結果

問題 No.1240 Or Sum of Xor Pair
ユーザー beetbeet
提出日時 2020-09-26 12:21:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 3,871 ms
コンパイル使用メモリ 201,928 KB
実行使用メモリ 86,680 KB
最終ジャッジ日時 2023-09-11 08:13:57
合計ジャッジ時間 15,798 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
85,420 KB
testcase_01 AC 24 ms
85,264 KB
testcase_02 AC 74 ms
85,300 KB
testcase_03 AC 151 ms
85,380 KB
testcase_04 AC 138 ms
85,440 KB
testcase_05 AC 179 ms
85,304 KB
testcase_06 AC 121 ms
85,320 KB
testcase_07 AC 146 ms
85,312 KB
testcase_08 AC 146 ms
85,568 KB
testcase_09 AC 135 ms
85,272 KB
testcase_10 AC 221 ms
85,356 KB
testcase_11 AC 193 ms
85,400 KB
testcase_12 AC 303 ms
85,380 KB
testcase_13 AC 357 ms
85,416 KB
testcase_14 AC 263 ms
85,260 KB
testcase_15 AC 823 ms
86,644 KB
testcase_16 AC 696 ms
86,436 KB
testcase_17 AC 657 ms
86,572 KB
testcase_18 AC 682 ms
86,428 KB
testcase_19 AC 593 ms
86,616 KB
testcase_20 AC 763 ms
86,380 KB
testcase_21 AC 712 ms
86,680 KB
testcase_22 AC 844 ms
86,572 KB
testcase_23 AC 509 ms
86,436 KB
testcase_24 AC 748 ms
86,432 KB
testcase_25 AC 406 ms
86,512 KB
testcase_26 AC 775 ms
86,536 KB
testcase_27 AC 49 ms
85,260 KB
testcase_28 AC 49 ms
85,360 KB
testcase_29 AC 100 ms
86,532 KB
testcase_30 AC 191 ms
85,800 KB
testcase_31 AC 136 ms
85,828 KB
testcase_32 AC 291 ms
86,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const ll LOG = 19;
ll all[1<<LOG]={};
ll cnt[LOG][1<<LOG]={};

signed main(){
  ll n,x;
  cin>>n>>x;
  vector<ll> as(n);
  for(ll &a:as) cin>>a;

  ll ans=0;
  for(ll i=0;i<LOG;i++){
    if((~x>>i)&1) continue;
    auto f=[&](ll a){return (a>>i)<<i;};

    memset(all,0,sizeof(all));
    for(ll a:as) all[f(a)]++;

    memset(cnt,0,sizeof(cnt));
    for(ll j=0;j<LOG;j++)
      for(ll a:as)
        cnt[j][f(a)]+=(a>>j)&1;

    ll y=(x>>(i+1))<<(i+1);
    for(ll j=0;j<LOG;j++){
      for(ll a:as){
        if((a>>j)&1) ans+=(all[y^f(a)]-(y==0))<<j;
        else ans+=(cnt[j][y^f(a)]-(y==0 and (a>>j)&1))<<j;
      }
    }
  }

  cout<<ans/2<<endl;
  return 0;
}
0