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. layui的动态下拉选

    <!--将授权问卷id全部查询出来--> <div class="layui-inline"> <label class="layui-fo ...

  2. 全面了解一致性哈希算法及PHP代码实现

    在设计一个分布式系统的架构时,为了提高系统的负载能力,需要把不同的数据分发到不同的服务节点上.因此这里就需要一种分发的机制,其实就是一种算法,来实现这种功能.这里我们就用到了Consistent Ha ...

  3. 让HTML5游戏来的更猛烈些吧!--青岛思途

    作为著名的网页游戏门户,Kongregate在业界也算是鼎鼎大名了.小编与它的初识应是在几年前,只记得当时其平台上的游戏基本都是需要Flash的支持,可前几天,Adobe宣布计划停止Flash的更新和 ...

  4. Codeforces 643G - Choosing Ads(线段树)

    Codeforces 题目传送门 & 洛谷题目传送门 首先考虑 \(p>50\) 的时候怎么处理,也就是求一个区间的绝对众数.我们知道众数这个东西是不能用线段树直接维护的,因为对于区间 ...

  5. [linux] mv: cannot move $ to $: Directory not empty

    最近测试某流程时,跑的过程报错了,于是检查脚本修改后重新测试.脚本是改过来了,但在shell中运行某步时碰到了如题报错! $ mv MP_genus_network_files/ tax_networ ...

  6. 62-Binary Tree Level Order Traversal

    Binary Tree Level Order Traversal My Submissions QuestionEditorial Solution Total Accepted: 102531 T ...

  7. window文件挂载到linux

  8. git添加新账号

    1,在linux上添加账号 useradd test passwd test usermod -G gitgroup  test  将test账号的组改为和git一样的组gitgroup  git所在 ...

  9. nrf51822 RAM不足分析

    之前了解过STM32 的内存分配问题,对于蓝牙芯片51822的内存分配问题把项目中,遇到了.bss和.data部分超了的问题,这其实就是声明的变量和stask 及 heap的大小总和超出了单片机的RA ...

  10. 05 Windows安装python3.6.4+pycharm环境

    windows安装python3.6.4环境 使用微信扫码关注微信公众号,并回复:"Python工具包",免费获取下载链接! 一.卸载python环境 卸载以下软件: 二.安装py ...