結果

問題 No.1072 A Nice XOR Pair
ユーザー CELICA
提出日時 2020-08-15 13:45:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 179,212 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-10-10 17:50:04
合計ジャッジ時間 3,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,x;
    cin >> n >> x;

    vector<ll> va(n);
    map<ll, ll> m;
    for (auto&& v : va)
    {
        cin >> v;
        ++m[v];
    }

    ll res{ 0 };
    if (x == 0)
    {
        for (const auto& im : m)
        {
            if (im.second > 1)
                res += im.second * (im.second-1) / 2;
        }
    }
    else
    {
        sort(va.begin(), va.end());
        auto result = std::unique(va.begin(), va.end());
        va.erase(result, va.end());

        for (const auto& v : va)
        {
            ll xx = v ^ x;

            if (m.count(xx))
                res += m[xx] * m[v];
        }

        res /= 2;
    }
    cout << res << "\n";

    return 0;
}
0