結果

問題 No.1240 Or Sum of Xor Pair
ユーザー SSRSSSRS
提出日時 2020-09-25 22:16:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 822 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 205,900 KB
実行使用メモリ 167,784 KB
最終ジャッジ日時 2023-09-10 15:32:05
合計ジャッジ時間 15,543 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
166,920 KB
testcase_01 AC 73 ms
166,892 KB
testcase_02 AC 75 ms
166,888 KB
testcase_03 AC 86 ms
166,856 KB
testcase_04 AC 87 ms
166,944 KB
testcase_05 AC 87 ms
166,984 KB
testcase_06 AC 83 ms
167,004 KB
testcase_07 AC 81 ms
166,944 KB
testcase_08 AC 82 ms
167,020 KB
testcase_09 AC 84 ms
166,948 KB
testcase_10 AC 148 ms
167,132 KB
testcase_11 AC 149 ms
167,208 KB
testcase_12 AC 219 ms
167,112 KB
testcase_13 AC 211 ms
167,192 KB
testcase_14 AC 198 ms
167,120 KB
testcase_15 AC 822 ms
167,708 KB
testcase_16 AC 729 ms
167,708 KB
testcase_17 AC 701 ms
167,636 KB
testcase_18 AC 753 ms
167,708 KB
testcase_19 AC 671 ms
167,784 KB
testcase_20 AC 778 ms
167,600 KB
testcase_21 AC 764 ms
167,656 KB
testcase_22 AC 791 ms
167,640 KB
testcase_23 AC 670 ms
167,648 KB
testcase_24 AC 734 ms
167,596 KB
testcase_25 AC 588 ms
167,624 KB
testcase_26 AC 736 ms
167,720 KB
testcase_27 AC 70 ms
166,852 KB
testcase_28 AC 72 ms
166,928 KB
testcase_29 AC 471 ms
167,628 KB
testcase_30 AC 188 ms
167,380 KB
testcase_31 AC 205 ms
167,460 KB
testcase_32 AC 411 ms
167,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int LOG = 19;
int main(){
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<long long>> sum(LOG, vector<long long>(1 << (LOG + 1), 0));
  vector<long long> cnt(1 << (LOG + 1), 0);
  for (int i = 0; i < N; i++){
    int v = 1;
    for (int j = 0; j <= LOG; j++){
      for (int k = 0; k < LOG; k++){
        if (A[i] >> k & 1){
          sum[k][v]++;
        }
      } 
      cnt[v]++;
      if (j < LOG){
        if (A[i] >> (LOG - 1 - j) & 1){
          v = v * 2 + 1;
        } else {
          v = v * 2;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    int v = 1;
    vector<int> id;
    for (int j = LOG - 1; j >= 0; j--){
      if (A[i] >> j & 1){
        if (X >> j & 1){
          id.push_back(v * 2 + 1);
          v = v * 2;
        } else {
          v = v * 2 + 1;
        }
      } else {
        if (X >> j & 1){
          id.push_back(v * 2);
          v = v * 2 + 1;
        } else {
          v = v * 2;
        }
      }
    }
    for (int x : id){
      for (int j = 0; j < LOG; j++){
        if (A[i] >> j & 1){
          ans += cnt[x] << j;
        } else {
          ans += sum[j][x] << j;
        }
      }
    }
  }
  for (int i = 0; i < N; i++){
    ans -= A[i];
  }
  cout << ans / 2 << endl;
}
0