CF742B.Arpa’s obvious problem and Mehrdad’s terrible solution
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that
, where
is bitwise xor operation (see notes for explanation).

Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
正如之前所提到的,Arpa 的国度里有一些漂亮的女孩。
某日,Arpa 想出了一个显然的问题:
给定一个数组和一个数 x,统计满足 1≤i<j≤n 的索引对 (i,j) 的数量,使得
,
其中
表示按位异或运算(参见注释了解详细说明)。

很快,Mehrdad 提出了一种可怕的解法,令所有人都不敢信任。现在,Arpa 需要你的帮助来实现该问题的正确解法。
输入格式
First line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the array and the integer x.
Second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105) — the elements of the array.
第一行包含两个整数 n 和 x(1≤n≤105,0≤x≤105)—— 分别表示数组的元素个数和整数 x。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤105)—— 表示数组的元素。
输出格式
Print a single integer: the answer to the problem.
输出一个整数:该问题的答案。
输入输出样例
输入#1
2 3 1 2
输出#1
1
输入#2
6 1 5 1 2 3 4 1
输出#2
2
说明/提示
In the first sample there is only one pair of i = 1 and j = 2.
so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since
) and i = 1, j = 5 (since
).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR.
在第一个样例中,只有一对 (i,j)=(1,2)。
,因此答案为 1。
在第二个样例中,仅有两对:(i,j)=(3,4)(因为
)和 (i,j)=(1,5)(因为
)。
按位异或(bitwise xor)运算作用于两个等长的二进制整数,对每一对对应位置上的比特执行逻辑异或操作。结果中每个位置上的比特值为 1,当且仅当两个操作数在该位置上的比特值恰好有一个为 1;若两个比特值均为 0 或均为 1,则结果中该位置上的比特值为 0。关于按位异或运算的更多内容,请参见:https://en.wikipedia.org/wiki/Bitwise_operation#XOR。
输入解题思路,AI测评打分。不知道怎么写?