B. Arpa’s obvious problem and Mehrdad’s terrible solution
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 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.
InputFirst 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.
OutputPrint a single integer: the answer to the problem.
Examplesinput2 3
1 2output1input6 1
5 1 2 3 4 1output2NoteIn 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.
#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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 【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 ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution
给出N*M矩阵,对于该矩阵有两种操作: 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都递增. *解法:N与M均为20,直接枚举所有可能的交换结果,进行判断 每次枚 ...
- CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解
Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...
- 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 ...
- 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,求每个子树中最长的边,满 ...
随机推荐
- 【面试 JVM】【第六篇】JVM调优
六部分内容: 一.内存模型 1.程序计数器,方法区,堆,栈,本地方法栈的作用,保存那些数据 可以画个大图出来,很清晰 jvm内存模型主要指运行时的数据区,包括5个部分. 栈也叫方法栈,是线程私有的,线 ...
- 一个炫酷的Actionbar效果
今天在网上看到一个炫酷的Actionbar效果,一个老外做的DEMO,目前很多流行的app已经加入了这个效果. 当用户初始进入该界面的时候,为一个透明的 ActiionBar ,这样利用充分的空间显示 ...
- Linux多线程实例 定时重启httpd和mysqld
#include <stdio.h> #include <pthread.h> void *start_routine(void *arg) { while(1) { syst ...
- C++类型的转换
C风格转换是“万能的转换”,但需要程序员把握转换的安全性,编译器无能为力:static_cast最接近于C风格转换,但在无关类指针转换时,编译器会报错,提升了安全性:dynamic_cast要求转换类 ...
- 性能測试JMeter趟的坑之JMeter的bug:TPS周期性波动问题
先说下问题: 我在做性能測试时,使用JMeter搞了100个并发,以100TPS的压力压測十分钟,但压力一直出现波动.并且出现波动时JMeter十分卡,例如以下图: 周期性TPS波动 各种猜測: 所以 ...
- UML类间关系
1继承 指的是一个类(称为子类.子接口)继承另外的一个类(称为父类.父接口)的功能,并可以增加它自己的新功能的能力,继承是类与类或者接口与接口之间最常见的关系:在Java中此类关系通过关键字exten ...
- cs6 mac 破解方法
Photoshop CS6 重点功能: 1.Photoshop CS6 包含Photoshop CS6和Photoshop CS6 Extended中所有功能,快去试一试3D图像编辑和Photosho ...
- Python调用C/Fortran混合的动态链接库--上篇
内容描述: 在32位或64位的windows或GNU/Linux系统下利用Python的ctypes和numpy模块调用C/Fortran混合编程的有限元数值计算程序 操作系统及编译环境: 32bit ...
- ajax的异步操作及页面重定向跳转
今天主要分享一个简单的ajax的异步操作数据,用javascript也有一段时间了,刚开始看到一些页面在没有页面刷新的情况下就可以实现数据的保存或者获取,觉得挺不可思议的,感觉速度很快,做了几个项目之 ...
- Spark 学习笔记:(四)MLlib基础
MLlib:Machine Learning Library.主要内容包括: 数据类型 统计工具 summary statistics correlations stratified sampling ...
, where
is bitwise xoroperation (see notes for explanation).
so the answer is 1.
) and i = 1, j = 5 (since
).