Content

有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数。其中 \(\oplus\) 表示异或符号。

数据范围:\(1\leqslant n,a_i\leqslant 10^5,0\leqslant x\leqslant 10^5\)。

Solution

利用一个异或的性质:\(a\oplus b=c\Rightarrow a\oplus c=b,b\oplus c=a\),我们发现问题其实就迎刃而解了。直接统计每个数异或 \(x\) 得到的数在原数组里面的个数再加起来就好了。

注意,数对可能很多,要开 \(\texttt{long long}\)。

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
using namespace std; int n, x, a[100007];
map<int, int> vis;
long long ans; int main() {
scanf("%d%d", &n, &x);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
ans += vis[a[i] ^ x];
vis[a[i]]++;
}
printf("%d", ans / 2);
return 0;
}

CF742B 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

    B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...

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

  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

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

  6. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  7. 枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution

    给出N*M矩阵,对于该矩阵有两种操作: 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都递增. *解法:N与M均为20,直接枚举所有可能的交换结果,进行判断 每次枚 ...

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

  9. 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,求每个子树中最长的边,满 ...

随机推荐

  1. JVM的Xms Xmx PermSize MaxPermSize区别

    Eclipse崩溃,错误提示:MyEclipse has detected that less than 5% of the 64MB of Perm Gen (Non-heap memory) sp ...

  2. Springboot .properties或.yml配置文件读取pom.xml文件值

    有时候配置文件需要读取pom文件配置<properties></properties>中间自定义属性值的时候可以用@@获取 例:@package.parameter@ 然后还需 ...

  3. npm 配置 registry 以及使用 nrm

    由于众所周知的原因,我们的内网链接互联网时非常不稳定,速度慢而且经常下载失败.为了提高下载安装 npm 包的体验,很多人都会把 npm 的 registry 配置成国内镜像,我们一般用的比较多的就是淘 ...

  4. 洛谷 P4709 - 信息传递(置换+dp)

    题面传送门 一道挺有意思的题罢-- 首先看到这种与置换乘法相关的题,首先把这些置换拆成一个个置换环,假设输入的置换有 \(m\) 个置换环,大小分别为 \(s_1,s_2,\cdots,s_m\),显 ...

  5. Codeforces 571E - Geometric Progressions(数论+阿巴细节题)

    Codeforces 题目传送门 & 洛谷题目传送门 u1s1 感觉此题思维难度不太大,不过大概是细节多得到了精神污染的地步所以才放到 D1E 的罢((( 首先我们对所有 \(a_i,b_i\ ...

  6. R语言hist重叠图作法

    set.seed(1) h1<-hist(rnorm(1000,100,5)) h2<-hist(rnorm(1000,99,5)) plot(h2,col=rgb(255,0,0,50, ...

  7. SSH客户端工具连接Linux(有的也可以连接Windows、mac、iOS等多系统平台)

    要远程操作Linux的话还是得靠SSH工具,一般来说,Linux是打开了默认22端口的SSH的服务端,如果我们要远程它的话,就需要一个SSH客户. 我对一款好用的工具主要需要满足以下几点. (1)连接 ...

  8. EXCEL-表格安全性:加密给与不同操作权限、表格怎么不让别人复制粘贴?

    1.下方表格名称右键-保护工作表,将所有选项取消勾选 然后设置一个密码就可以了 2.文件旁的三条线点开-选项-安全性,设置编辑权限密码,确定

  9. mysql-日期时间函数大全

    DAYOFWEEK(date)  返回日期date是星期几(1=星期天,2=星期一,--7=星期六,ODBC标准)mysql> select DAYOFWEEK('1998-02-03');  ...

  10. 学习java的第二十三天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...