Codeforces 742B B. Arpa’s obvious problem and Mehrdad’s terrible solution
1 second
256 megabytes
standard input
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 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.
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.
Print a single integer: the answer to the problem.
2 3 1 2
1
6 1 5 1 2 3 4 1
2
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 b = x^a 由b找到a 一个循环搞定!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;
while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')
fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,
rx=getchar();return ra*fh;}
//#pragma comment(linker, "/STACK:102400000,102400000")
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}ll n,x,t1;
ll a[1000005];int main()
{ios::sync_with_stdio(false); ll ct = 0;cin >> n >> x;for(int i=1;i<=n;i++){cin >> t1;ll t = t1^x;ct += a[t];a[t1]++;}cout << ct <<endl;return 0;
}
Codeforces 742B B. Arpa’s obvious problem and Mehrdad’s terrible solution相关推荐
- Codeforces 742B 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 solutio ...
- CF 742 B-Arpa’s obvious problem and Mehrdad’s terrible solution
传送门 : CF 742B 题解 异或逆运算 AC code: /*adrui's submission Language : C++ Result : Accepted Lover : zyy Fa ...
- Codeforces 741 D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
D - Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 思路: 树上启发式合并 从根节点出发到每个位置的每个字符的奇偶性记为每个位 ...
- 【Codeforces 741 B. Arpa's weak amphitheater and Mehrdad's 】+ 并查集 + 01背包
B. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...
- 【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 ...
- Codeforces 742 C Arpa's loud Owf and Mehrdad's evil plan
题目地址:http://codeforces.com/contest/742/problem/C 题意:我看了好多别人的博客的对于题意的理解,结合他们的代码我认为这道题的意思应该是每个数要都能经过t步 ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses —— DP(01背包)
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable ...
- CodeForces - 742B
There are some beautiful girls in Arpa's land as mentioned before. Once Arpa came up with an obvious ...
- Codeforces 798C:Mike and gcd problem
Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...
最新文章
- sklearn数据处理_one_hot
- idea中配置xml不自动提示解决方案
- python练习---模拟sql
- 007 Android之Broadcast Receiver
- android 简单实现圆角,Android 实现圆角图片的简单实例
- timer控件的使用
- tomcat的jdbc连接池PoolExhaustedException 1
- Kaldi AMI数据集脚本学习1----cmd.sh和path.sh
- 灵活运用用第3方软件把“SWF”变回“FLA”
- 两相四线步进电机的驱动
- 【Heydrones】飞手百科第一篇:一定要看的无人机原理总结
- 测试开发(社招)面经:度小满
- R 运行中文文件使乱码的解决方案(案例示例)
- c语言各种输出错误提示,C语言错误处理-输出错误信息
- 计算机软件可以授予专利权吗,软件产品能申请专利吗?
- 盒子装载图片时出现的盒子比图片实际偏高的问题
- 如何截取视频中的一部分制作成GIF动态图
- 3、TextBox 控件
- 使用python计算复利
- B2B,B2C和C2C