time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

 

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 xoroperation (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.

Examples
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.

 
题意:
找出给定数列里两两异或值为x的组合个数
 
a^b=x; x^a=b; x^b=a;
x已经给定 我们只需循环a找是否有b与之对应。
 
附AC代码:
 #include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
map<int ,int > m;
int n,x;
cin>>n>>x;
for(int i=;i<=n;i++){
scanf("%d",a+i);
}
long long ans=;
for(int i=;i<=n;i++){
if(m.count(x^a[i])) //找到返回1 否则返回0
ans+=m[x^a[i]];
m[a[i]]++;
}
cout<<ans<<endl;
return ;
}
 

B. 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. Arpa’s obvious problem and Mehrdad’s terrible solution 思维

    There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious ...

  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. 【hibernate/JPA】注解方式实现 复合主键【spring boot】

    1>hibernate/JPA实现复合主键的思路:是将所有的主键属性封装在一个主键类中,提供给需要复合主键的实体类使用. 2>主键类的几点要求: . 使用复合主键的实体类必须实现Seria ...

  2. ScSPM

    Linear Spatial Pyramid Matching using Sparse Coding for Image Classification (CVPR'09) 稀疏编码系列: (一)-- ...

  3. weex stream 方法封装

    1.封装 api.js // 配置API接口地址 const baseUrl = 'http://www.kuitao8.com/'; // 引入 弹窗组件 var modal = weex.requ ...

  4. Java学习之集合

    1.ArrayList:采用数组的形式保存对象,这种方式将对象保存在连续的位置中,所以查询效率比较高,但是插入删除时麻烦,并且ArrayList不是线程安全的. 2.Vector:保存对象的方式与Ar ...

  5. eImage(仅两行代码实现输出从数据库中查询到的二进制字段)标签

    功能: 专门用于向浏览器输出从数据库中查询到的二进制字段.支持通用的几十种文件类型 别名为edoc 使用方法: <chtml><eimage id=书包名type=类型>key ...

  6. WebService Get/Post/Soap 方式请求

    import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.InputStream; im ...

  7. 编译异常之static和extern---more than one storage class specified

    static 和 extern 不能同时共存 http://bbs.bccn.net/thread-58129-1-1.html

  8. VC++中全局变量的问题(转)

    全局变量一般这样定义:1.在一类的.cpp中定义 int myInt;然后再在要用到的地方的.cpp里extern int myInt:这样就可以用了. 2.在stdafx.cpp中加入:int my ...

  9. Spring Boot JPA 连接数据库

    本文将介绍怎样在Spring Boot project中加入JPA作为持久化方式. 改动 pom.xml 依赖 与上一篇介绍的 jdbc 不同的是 spring-boot-starter-jdbc 改 ...

  10. SKStoreReviewController之程序内评价

    在iOS 10.3出现之前,App实现评价方式一般有两种: (一)deep link调用.在app 链接地址后面拼上action=write-review这种方式可以实现程序内评价: (二)App跳转 ...