結果

問題 No.1240 Or Sum of Xor Pair
ユーザー beetbeet
提出日時 2020-09-25 22:49:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 629 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 200,332 KB
実行使用メモリ 43,740 KB
最終ジャッジ日時 2023-09-10 16:01:43
合計ジャッジ時間 11,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
42,432 KB
testcase_01 AC 12 ms
42,292 KB
testcase_02 AC 35 ms
42,420 KB
testcase_03 AC 72 ms
42,472 KB
testcase_04 AC 67 ms
42,340 KB
testcase_05 AC 80 ms
42,320 KB
testcase_06 AC 56 ms
42,316 KB
testcase_07 AC 66 ms
42,312 KB
testcase_08 AC 64 ms
42,484 KB
testcase_09 AC 61 ms
42,640 KB
testcase_10 AC 123 ms
42,428 KB
testcase_11 AC 111 ms
42,292 KB
testcase_12 AC 187 ms
42,472 KB
testcase_13 AC 214 ms
42,304 KB
testcase_14 AC 163 ms
42,376 KB
testcase_15 AC 618 ms
43,548 KB
testcase_16 AC 493 ms
43,624 KB
testcase_17 AC 484 ms
43,684 KB
testcase_18 AC 502 ms
43,648 KB
testcase_19 AC 431 ms
43,740 KB
testcase_20 AC 569 ms
43,548 KB
testcase_21 AC 536 ms
43,692 KB
testcase_22 AC 629 ms
43,620 KB
testcase_23 AC 361 ms
43,604 KB
testcase_24 AC 560 ms
43,648 KB
testcase_25 AC 280 ms
43,600 KB
testcase_26 AC 577 ms
43,564 KB
testcase_27 AC 24 ms
42,492 KB
testcase_28 AC 24 ms
42,308 KB
testcase_29 AC 46 ms
43,548 KB
testcase_30 AC 115 ms
42,904 KB
testcase_31 AC 77 ms
42,776 KB
testcase_32 AC 174 ms
43,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE

const Int LOG = 18;
Int all[1<<LOG]={};
Int cnt[LOG][1<<LOG]={};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,x;
  cin>>n>>x;
  auto as=read(n);

  Int k=LOG;
  while((~x>>k)&1) k--;

  Int ans=0;
  for(Int i=0;i<=k;i++){
    if((~x>>i)&1) continue;
    Int y=(x>>(i+1))<<(i+1);

    memset(all,0,sizeof(all));
    for(Int a:as) all[(a>>i)<<i]++;

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

    for(Int j=0;j<LOG;j++)
      for(Int a:as)
        if((a>>j)&1) ans+=(all[y^((a>>i)<<i)]-(y==0))*(1<<j);
        else ans+=(cnt[j][y^((a>>i)<<i)]-(y==0 and (a>>j)&1))*(1<<j);
  }
  cout<<ans/2<<newl;
  return 0;
}
0