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.

Input

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 a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array.

Output

Print a single integer: the answer to the problem.

Example

Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2

Note

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.

这道题一开始没看懂啥意思,后来才明白原来是异或^,a^b=c,那么a^c=b;抓住这一点就好做了,所有的ai去异或x得到cnt,然后记录cnt,看看数组里面有几个cnt就好了,可以开个map,注意结果可能超过long 要用long long

代码:

#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int n,x,a[];
map<int,int> mark;
void input()
{
cin>>n>>x;
for(int i=;i<n;i++)
{
cin>>a[i];
mark[a[i]]++;
}
}
long long check()
{
long long cnt,ans=;
for(int i=;i<n;i++)
{
cnt=a[i]^x;
///x如果是0 那么 任意一个数q q^0=q;
if(a[i]==cnt)ans+=mark[cnt]-;
else ans+=mark[cnt];
}
return ans/;
}
int main()
{
input();
cout<<check();
}

Arpa’s obvious problem and Mehrdad’s terrible solution 思维的更多相关文章

  1. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution

    B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...

  2. Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或

    题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...

  3. B. Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  6. 枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution

    给出N*M矩阵,对于该矩阵有两种操作: 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都递增. *解法:N与M均为20,直接枚举所有可能的交换结果,进行判断 每次枚 ...

  7. CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解

    Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...

  8. Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...

  9. CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]

    D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...

随机推荐

  1. JSON自定义排序

    var json=[{ Name:'张三', Addr:'重庆', Age:'20' },{ Name:'张三3', Addr:'重庆2', Age:'25' },{ Name:'张三2', Addr ...

  2. English trip -- Review Unit8 Work 工作

    工作一般询问对方的工作情况的方式: What job is it?  它的工作是什么? You're a engineer?     你是工程师? Right  是的 What do you do?  ...

  3. 多线程(JDK1.5的新特性互斥锁)

    多线程(JDK1.5的新特性互斥锁)(掌握)1.同步·使用ReentrantLock类的lock()和unlock()方法进行同步2.通信·使用ReentrantLock类的newCondition( ...

  4. 20170724wdVBA正则表达式提取答案到Excel

    Public Sub RegExtractData() Dim StartTime, UsedTime StartTime = VBA.Timer Dim FilePath$ Dim FileName ...

  5. Confluence 6 为站点禁用匿名用户访问

    希望为你的站点禁用匿名用户的访问,取消选择 可以使用(can use)前面的选择框,然后选择 保存所有(Save All).这时候,用户应该禁止访问你的站点直达这些用户登录你的 Confluence ...

  6. SAS/SATA/SSD/IDE硬盘介绍区别

    SAS/SATA/SSD/IDE硬盘介绍区别 SAS(Serial Attached SCSI)即串行连接SCSI,是新一代的SCSI技术,和现在流行的Serial ATA(SATA)硬盘相同,都是采 ...

  7. python-day46--前端基础之html

    一.html是什么? 超文本标记语言(Hypertext Markup Language,HTML)通过标签语言来标记要显示的网页中的各个部分.一套规则,浏览器认识的规则 浏览器按顺序渲染网页文件,然 ...

  8. BZOJ2590 [Usaco2012 Feb]Cow Coupons

    好吧...想了半天想错了...虽然知道是贪心... 我们每次找没有被买的两种价格最小的牛,比较a = 当前差价最大的 + 当前优惠券价格最小的牛与b = 当前非优惠券价格最小的牛 所以...我们要 先 ...

  9. 数据库cmd窗口登录

    mysql -uroot -p123 -P3306 -h127.0.0.1 -uroot::root数据库登录用户名 -p123:数据库密码123 -P3306::3306数据库的端口号 -h127. ...

  10. 6.pragma pack

    下面两个结构体 struct One { double d; char c; int i; } struct Two { char c; double d; int i; } 在#pragma pac ...