結果
問題 |
No.1072 A Nice XOR Pair
|
ユーザー |
![]() |
提出日時 | 2020-06-05 22:25:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,769 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 177,172 KB |
実行使用メモリ | 9,968 KB |
最終ジャッジ日時 | 2024-12-17 16:09:06 |
合計ジャッジ時間 | 2,747 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 WA * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repr(i,n) for(int i = (int)(n); i >= 0; i--) #define all(v) v.begin(),v.end() typedef long long ll; int main(){ ll N,X; cin >> N >> X; vector<ll> vec(N); rep(i,N){ cin >> vec[i]; } sort(all(vec)); vector<pair<ll,ll> > count(0); count.push_back(pair<ll,ll> (-1,1)); rep(i,N){ if (vec[i] != count[count.size() - 1].first){ count.push_back(pair<ll,ll> (vec[i],1)); } else{ count[count.size() - 1].second++; } } ll len = count.size(); ll ans = 0; rep(i,N){ ll ans_sub = vec[i] ^ X; if (count[len - 1].first > ans_sub){ ans += 0; } else if (count[len - 1].first == ans_sub){ ans += count[len - 1].second; } else{ int left = 0; int right = len - 1; while(true){ if (right - left == 1){ if (count[left].first == ans_sub){ ans += count[left].second; } else{ ans += 0; } break; } else if (count[(left + right) / 2].first <= ans_sub){ left = (left + right) / 2; } else{ right = (left + right) / 2; } } } } ll special_ans = 0; if (X == 0){ rep(i,len){ special_ans += (count[i].second - 1) * (count[i].second) / 2; } cout << special_ans << endl; } else{ cout << ans << endl; } }