結果

問題 No.1072 A Nice XOR Pair
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-06-08 20:35:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 1,332 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 96,172 KB
実行使用メモリ 44,928 KB
最終ジャッジ日時 2024-04-21 10:29:18
合計ジャッジ時間 3,756 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 434 ms
28,288 KB
testcase_08 AC 84 ms
5,376 KB
testcase_09 AC 82 ms
5,376 KB
testcase_10 AC 94 ms
5,376 KB
testcase_11 AC 281 ms
18,432 KB
testcase_12 AC 526 ms
44,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n,x;
  cin>>n>>x;
  map<ll,ll> ma1;
  map<ll,ll> ma2;
  rep(i,0,n){
    ll a;
    cin>>a;
    ma1[a]++;
  }
  ll ans = 0;
  if(x==0){
    map<ll,ll>::iterator itr = ma1.begin();
    while(itr!=ma1.end()){
      ll b = (*itr).se;
      ans += b*(b-1)/2;
      itr++;
    }
  }
  else{
    map<ll,ll>::iterator itr = ma1.begin();
    while(itr!=ma1.end()){
      ll a = (*itr).fi;
      ll b = (*itr).se;
      if(ma2[a]==0){
        ans += b*ma1[a^x];
        ma2[a]=1;
        ma2[a^x]=1;
      }
      itr++;
    }
  }
  cout << ans << endl;
  return 0;
}
0