結果

問題 No.1240 Or Sum of Xor Pair
ユーザー beetbeet
提出日時 2020-09-26 12:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 776 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 200,388 KB
実行使用メモリ 86,856 KB
最終ジャッジ日時 2023-09-11 08:00:25
合計ジャッジ時間 14,705 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
85,524 KB
testcase_01 AC 23 ms
85,480 KB
testcase_02 AC 70 ms
85,304 KB
testcase_03 AC 142 ms
85,400 KB
testcase_04 AC 130 ms
85,336 KB
testcase_05 AC 170 ms
85,240 KB
testcase_06 AC 115 ms
85,264 KB
testcase_07 AC 139 ms
85,276 KB
testcase_08 AC 139 ms
85,220 KB
testcase_09 AC 128 ms
85,396 KB
testcase_10 AC 205 ms
85,252 KB
testcase_11 AC 183 ms
85,372 KB
testcase_12 AC 282 ms
85,268 KB
testcase_13 AC 333 ms
85,248 KB
testcase_14 AC 248 ms
85,424 KB
testcase_15 AC 768 ms
86,856 KB
testcase_16 AC 631 ms
86,600 KB
testcase_17 AC 609 ms
86,560 KB
testcase_18 AC 650 ms
86,604 KB
testcase_19 AC 558 ms
86,572 KB
testcase_20 AC 720 ms
86,552 KB
testcase_21 AC 666 ms
86,600 KB
testcase_22 AC 776 ms
86,608 KB
testcase_23 AC 472 ms
86,596 KB
testcase_24 AC 695 ms
86,592 KB
testcase_25 AC 376 ms
86,712 KB
testcase_26 AC 721 ms
86,600 KB
testcase_27 AC 47 ms
85,304 KB
testcase_28 AC 47 ms
85,304 KB
testcase_29 AC 97 ms
86,696 KB
testcase_30 AC 181 ms
85,804 KB
testcase_31 AC 128 ms
85,772 KB
testcase_32 AC 272 ms
86,524 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))*(1<<j);
        else ans+=(cnt[j][y^f(a)]-(y==0 and (a>>j)&1))*(1<<j);
      }
    }
  }

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