time limit per test1 second

memory limit per test256 megabytes

inputstandard input

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

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.

【题目链接】:http://codeforces.com/contest/742/problem/B

【题解】



用个map记录1..i-1里面x xor a[i]的值有多少个;

则那些数字都能和a[i]进行xor运算取得a[i];

因为 a xor b = c

则c xor b = a

且c xor a = b;

O(n)枚举搞一下就好;



【完整代码】

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cmath>
  4. #include <set>
  5. #include <map>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <cstring>
  9. #include <queue>
  10. #include <vector>
  11. #include <stack>
  12. #include <string>
  13. using namespace std;
  14. #define lson l,m,rt<<1
  15. #define rson m+1,r,rt<<1|1
  16. #define LL long long
  17. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  18. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  19. #define mp make_pair
  20. #define pb push_back
  21. #define fi first
  22. #define se second
  23. typedef pair<int,int> pii;
  24. typedef pair<LL,LL> pll;
  25. void rel(LL &r)
  26. {
  27. r = 0;
  28. char t = getchar();
  29. while (!isdigit(t) && t!='-') t = getchar();
  30. LL sign = 1;
  31. if (t == '-')sign = -1;
  32. while (!isdigit(t)) t = getchar();
  33. while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
  34. r = r*sign;
  35. }
  36. void rei(int &r)
  37. {
  38. r = 0;
  39. char t = getchar();
  40. while (!isdigit(t)&&t!='-') t = getchar();
  41. int sign = 1;
  42. if (t == '-')sign = -1;
  43. while (!isdigit(t)) t = getchar();
  44. while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
  45. r = r*sign;
  46. }
  47. const int MAXN = 1e5+100;
  48. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  49. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  50. const double pi = acos(-1.0);
  51. int n,x;
  52. int a[MAXN];
  53. map <int,int> dic;
  54. int main()
  55. {
  56. // freopen("F:\\rush.txt","r",stdin);
  57. scanf("%d%d",&n,&x);
  58. rep1(i,1,n)
  59. scanf("%d",&a[i]);
  60. LL ans = 0;
  61. rep1(i,1,n)
  62. {
  63. if (dic[a[i]^x])
  64. ans+=dic[a[i]^x];
  65. dic[a[i]]++;
  66. }
  67. cout << ans << endl;
  68. return 0;
  69. }

【codeforces 742B】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 —— 异或

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

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

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

  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 742C】Arpa's loud Owf and Mehrdad's evil plan

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

  9. 【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat

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

随机推荐

  1. Monkey测试执行指导

    1.Monkey常规测试

  2. SSO单点登录学习总结(2)——基于Cookie+fliter单点登录实例

    1.使用Cookie解决单点登录 技术点: 1.设置Cookie的路径为setPath("/").即Tomcat的目录下都有效 2.设置Cookie的域setDomain(&quo ...

  3. COGS——T 1265. [NOIP2012] 同余方程

    http://cogs.pro/cogs/problem/problem.php?pid=1265 ★☆   输入文件:mod.in   输出文件:mod.out   简单对比时间限制:1 s   内 ...

  4. 洛谷 P1334 瑞瑞的木板

    P1334 瑞瑞的木板 题目描述 瑞瑞想要亲自修复在他的一个小牧场周围的围栏.他测量栅栏并发现他需要N(1≤N≤20,000)根木板,每根的长度为整数Li(1≤Li≤50,000).于是,他神奇地买了 ...

  5. mysql-cacti-templates-1.1.2.tar.gz 免费下载 cacti MySQL添加监控

    cacti MySQL添加监控 1. 安装监控插件 wget http://mysql-cacti-templates.googlecode.com/files/mysql-cacti-templat ...

  6. 深度学习 Deep Learning UFLDL 最新Tutorial 学习笔记 3:Vectorization

    1 Vectorization 简述 Vectorization 翻译过来就是向量化,各简单的理解就是实现矩阵计算. 为什么MATLAB叫MATLAB?大概就是Matrix Lab,最根本的差别于其它 ...

  7. 3. ZAB与Paxos算法的联系与区别。

    转自:https://blog.csdn.net/en_joker/article/details/78665809 ZAB协议并不是Paxos算法的一个典型实现,在讲解ZAB和Paxos之间的区别之 ...

  8. js进阶 13 jquery动画函数有哪些

    js进阶 13 jquery动画函数有哪些 一.总结 一句话总结: 二.jquery动画函数有哪些 原生JavaScript编写动画效果代码比较复杂,而且还需要考虑兼容性.通过jQuery,我们使用简 ...

  9. Android Gradle统一依赖管理

    目的: 避免在依赖包出新版本时,需要对每个module中的build.gradle文件都进行修改(如appcompat-v7包),使用这种方式即只需一次修改. 方法一 在项目的根目录创建一个gradl ...

  10. Redo current损坏

       如果损坏的是current redo log (select group#,sequence#,archived,status from v$log;) 有两种情况: A.   数据库是正常关闭 ...