博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces742B
阅读量:5258 次
发布时间:2019-06-14

本文共 3030 字,大约阅读时间需要 10 分钟。

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

 

sol:询问有多少对i,j满足ai^aj = X,这就是Trie树可以轻松支持的,只要注意下X=0时的情况就可以了

Ps:答案会爆int

#include 
using namespace std;typedef long long ll;inline ll read(){ ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s);}#define R(x) x=read()inline void write(ll x){ if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return;}#define W(x) write(x),putchar(' ')#define Wl(x) write(x),putchar('\n')const int N=100005;int n,Num,a[N];struct Zidianshu{ int Trie[N*25][25],cnt; int End[N*25]; inline void Init() { cnt=0; } inline void Insert(int Num) { int i,Root=0; for(i=0;i<=23;i++) { int oo=(Num&(1<
>i; if(!Trie[Root][oo]) Trie[Root][oo]=++cnt; Root=Trie[Root][oo]; } End[Root]++; } inline int Query(int Num,int Want) { int i,Root=0; for(i=0;i<=23;i++) { int oo=((Want&(1<
>i)^((Num&(1<
>i); if(!Trie[Root][oo]) return 0; Root=Trie[Root][oo]; } return End[Root]; }}Trie;int main(){ Trie.Init(); int i; long long ans=0; R(n); R(Num); for(i=1;i<=n;i++) { a[i]=read(); ans+=1ll*Trie.Query(a[i],Num); Trie.Insert(a[i]); } Wl(ans); return 0;}/*input2 31 2output1input6 15 1 2 3 4 1output2input10 01 2 1 2 1 2 1 2 1 2output20*/
View Code

 

转载于:https://www.cnblogs.com/gaojunonly1/p/10629371.html

你可能感兴趣的文章
多进程与多线程的区别
查看>>
Ubuntu(虚拟机)下安装Qt5.5.1
查看>>
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
查看>>
java 常用命令
查看>>
CodeForces Round #545 Div.2
查看>>
卷积中的参数
查看>>
51nod1076 (边双连通)
查看>>
Item 9: Avoid Conversion Operators in Your APIs(Effective C#)
查看>>
深入浅出JavaScript(2)—ECMAScript
查看>>
STEP2——《数据分析:企业的贤内助》重点摘要笔记(六)——数据描述
查看>>
ViewPager的onPageChangeListener里面的一些方法参数:
查看>>
Jenkins关闭、重启,Jenkins服务的启动、停止方法。
查看>>
CF E2 - Array and Segments (Hard version) (线段树)
查看>>
Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
查看>>
SIGPIPE并产生一个信号处理
查看>>
CentOS
查看>>
Linux pipe函数
查看>>
java equals 小记
查看>>
爬虫-通用代码框架
查看>>
2019春 软件工程实践 助教总结
查看>>