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,求每个子树中最长的边,满 ...
随机推荐
- SSD TRIM
SSD 在操作方式上与传统磁性驱动器不同,并且它们需要在软件上另行处理以达到功能优化.-- Don Watkins 编译自: https://opensource.com/article/17/1/s ...
- mysql explain 的type解释
原文:http://blog.csdn.net/github_26672553/article/details/52058782 Explain命令 用于分析sql语句的执行情况和成本预估 今天我们重 ...
- Eclipse FindBugs的安装
原文:http://blog.sina.com.cn/s/blog_62186b460100l3mx.html 1安装:首先到官方网站下载最新版本FindBugs http://findbugs ...
- BUPT复试专题—打牌(2011)
https://www.nowcoder.com/practice/82442ee76977479e8ab4b88dfadfca9f?tpId=67&tqId=29640&tPage= ...
- ceph工作原理和安装
一.概述 Ceph是一个分布式存储系统,诞生于2004年,最早致力于开发下一代高性能分布式文件系统的项目.随着云计算的发展,ceph乘上了OpenStack的春风,进而成为了开源社区受关注较高的项目之 ...
- python web框架企业实战具体解释(第六期)\第三课时-ajax&jquery&webpy
main.py __author__ = 'Liao' import web import time urls = ( '/gettime','gettime', '/(.*)', 'hello' ) ...
- sqlite学习笔记10:C语言中使用sqlite之查询和更新数据
前面说到的 sqlite_exec() 中的第三个參数, SQLite 将为 sql 參数内运行的每一个 SELECT 语句中处理的每一个记录调用这个回调函数. 本节加入了两个函数.selectFro ...
- Android开发Tips(3)
欢迎Follow我的GitHub, 关注我的CSDN. 我会介绍关于Android的一些有趣的小知识点. 本文是第三篇, 其余第一篇, 第二篇. imageMogr2/auto-orient/stri ...
- Android应用程序窗体View的创建过程
View类是android中非常重要的一个类.view是应用程序界面的直观体现,我们看到的应用程序界面就能够看作是View(视图)组成的. 那么我们应用程序的界面是怎么创建的呢,也就是应用程序的Vie ...
- Mysql中show processlist结果中的status状态总结
一 般情况下,DBA能从监控mysql的状态列表中查看出数据库的运行端倪,需要注意的是STATUS所表示的不同内容.且需要注意的是TIME字段表示的 意思.它表示的只是最后那个STAT状态持续的时间. ...
, where
is bitwise xoroperation (see notes for explanation).
so the answer is 1.
) and i = 1, j = 5 (since
).