結果

問題 No.1072 A Nice XOR Pair
ユーザー AngrySadEightAngrySadEight
提出日時 2020-06-05 22:25:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,769 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 175,440 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2024-05-09 21:59:11
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 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 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 86 ms
5,376 KB
testcase_10 AC 92 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0