結果

問題 No.1240 Or Sum of Xor Pair
ユーザー beet
提出日時 2020-09-26 12:09:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 2,838 ms
コンパイル使用メモリ 194,632 KB
最終ジャッジ日時 2025-01-14 22:07:49
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

const ll LOG = 18;
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