Codeforces 742B

H3C交换机Console口连接全攻略:从接线到PuTTY配置(附常见问题排查) 本文详细介绍了H3C交换机Console口的连接与配置方法,包括硬件线缆选择、驱动安装、PuTTY参数设置及常见问题排查。特别针对Console转USB线缆的兼容性和驱动安装难点提供实用建议,帮助网络工程师快速掌握串联调试技巧,解决连接中的黑屏、乱码等典型问题。 阅读详情

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.

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

Output
Print a single integer: the answer to the problem.

Example
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
Note
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.

没有搞清楚异或的用法 a^b=x, a=b^x.
而且另一个需要知道的是 异或的优先级比==低 所以好多次都没出结果。穷举连答案都出不了,虽然这道题不应该用穷举。
错误代码

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int a[250010];
int main()
{
    int n,x;
    while(cin>>n>>x)
    {
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                if(a[i]^a[j]==x)   //这里错了,应该改为if((a[i]^a[j])==x)  
                    cout<<a[i]<<" "<<a[j]<<endl;
            }
        }
    }
}

正确代码 注意10的5次方会到10万用LL

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
LL a[250010];
LL cnt[250010];
int main()
{
    int n,x;
    while(cin>>n>>x)
    {
        LL ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            cnt[a[i]]++;
        }
        for(int i=0;i<n;i++)
        {
            cnt[a[i]]--;
            LL t=a[i]^x;
            ans+=cnt[t];
        }
        cout<<ans<<endl;
    }
}
从东南大学906被刷到调剂过程(内含个人感想) 介绍了自己在看到初试成绩,到后期复习以及调剂的全过程,当中也包含了自己的复试中的感想,希望大家理性看待。 阅读详情

相关推荐

Zemax新手别慌!一文搞懂几何像差:从球差、慧差到色差的实战识别与优化

本文为Zemax新手提供几何像差实战指南,详细解析球差、彗差和色差的识别与优化方法。通过软件操作关键节点和实际项目决策逻辑,帮助光学设计师快速掌握像差诊断与优化技巧,提升光学设计效率。

weixin_42524708的博客 264

CodeForces742b

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

NineFailure的博客 621

《Halcon 100项目-9》Halcon彩色线序检查

Halcon彩色线序检查

doubleintfloat的博客 1050

codeforces742B

Arpa’s obvious problem and Mehrdad’s terrible solution CodeForces - 742B There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an ar...

weixin_30846599的博客 162

2025.06.25【微生物】|Emu工具安装与使用详解:全长16S扩增子微生物丰度分析

Emu是一款基于贝叶斯方法的微生物多样性分析工具,专为处理高错误率的长读长16S/18S扩增子数据优化。本文详细介绍了Emu的安装与使用方法:1)通过conda创建独立环境并安装Emu;2)提供SILVA等预构建数据库的下载指南,并说明自定义数据库的构建方法;3)演示单样本和多样本分析流程,解读关键输出文件;4)介绍丰度表合并、分类等级汇总等实用功能扩展;5)建议后续分析方向。文章还附有官方GitHub链接和相关文献资源,为微生物群落结构研究提供了一套完整的分析解决方案。

1259

深入Android构建系统:一次修改ro.vendor.build.fingerprint失败的排查与解决记录

本文深入探讨了Android构建系统中修改ro.vendor.build.fingerprint的完整解决方案。通过分析vendor分区的特殊地位和构建指纹的生成路径,提供了三种实战修改方法,并揭示了指纹修改可能遇到的陷阱与对策,帮助开发者彻底解决这一常见问题。

weixin_30621711的博客 154

codeforces 742B

#include #include #include using namespace std; int a[100010]; int main() { int n,x; scanf("%d%d",&n,&x); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); int k=0,l=0; long

sinat_35121480的博客 612

Edge浏览器IE模式失效?最新142版本隐藏按钮的3种解决方案

本文针对Edge浏览器142版本中IE模式按钮消失的问题,提供了3种实用解决方案,包括注册表修改、手动添加网站到IE模式列表和企业策略部署方案,帮助用户解决兼容性问题,确保老旧系统正常访问。

weixin_28308325的博客 521

CodeForces - 742B

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)

dreambyday 761

原理图分享二(信盈达CorexM4核心板STM32F407VGT6)

这是第二张板子的原理图分享,这也是当时大学里学习的一个板子。 原理图分享二(信盈达CorexM4核心板STM32F407VGT6)

让学习成为一种习惯 6915

【网络安全 | 渗透工具】Githack工具安装及使用教程详析

本文仅分享Githack工具基本安装及使用相关知识不承担任何法律责任。Git是一个非常流行的开源分布式版本控制系统,它被广泛用于协同开发和代码管理。许多网站和应用程序都使用Git作为其代码管理系统,并将其部署到生产环境中以维护其代码库。然而,在配置不当的情况下,可能会导致.git文件夹被直接部署到线上环境中,这可能会导致Git泄露问题。可通过githack下载泄露的Git存储库,以获取包含未加密密码、凭据和敏感信息的站点代码库。使用githack下载Git存储库的方法有两种。本文仅分享。

等风来 3万+

Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution

思路:a[i] ^ a[j] = x -> a[j]^x = a[i], 读入的时候找到前面有多少个对应的a[j]^x加上即可。 找的时候最大可能是2^17-1,所以数组要开的大一点。 代码: #include using namespace std; const int maxn = 1e6+5; typedef long long ll; int book[maxn], n, x

CillyB的博客 1060

SAP-ABAP:SAP中的用户确认对话框:深入理解与实践POPUP_TO_CONFIRM

本文深入介绍了SAP中的用户确认对话框函数POPUP_TO_CONFIRM,包括其核心参数配置、返回值处理、应用场景和最佳实践。该函数是SAP二次开发中重要的交互工具,用于关键操作前获取用户确认,防止误操作。文章详细解析了参数设置技巧,强调必须全面处理所有可能的返回值,并提供了删除数据、批量操作等典型应用场景的代码示例。同时对比了其他类似弹出函数,帮助开发者选择合适工具。正确使用该函数可提升系统安全性、改善用户体验并符合SAP设计规范。

baidu_35680696的博客 974

Codeforces Round #742 (Div. 2) B. MEXor Mixup

B. MEXor Mixup 原题链接 题目大意: 让你构造一个 mex 为a,xor和为b的序列 问最小的序列长度 思路: 首先因为mex为a,所以[0,a-1]都是必须选的 我们可以预处理出他的异或和sum 如果sum[ a - 1 ] = b 那么答案是 a 对于不等于的,我们都能找到一个数与其异或得到b 但是还需要考虑其mex是否不为a,也就是 b ^ sum[ a - 1 ]恰好就是 a 这时候我们就必须两个数了 如果( sum[ a - 1 ] ^ b ) = a 那么答案就是a + 2 如

遗落之辉的博客 347

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces Round #742 (Div. 2)--B. MEXor Mixup

Codeforces Round #742 (Div. 2)–B. MEXor Mixup 思路 首先知道确定一个异或的数a和异或后的值x满足a^b=x,那么有且只有一个b满足该等式 数组的最小长度肯定是大于等于a的,所以先让ans=a 首先初始化将1到n的异或的值全都筛选出来保存到一个数组中 如果异或的值等于b的话,那么答案就是a,否则,将得到的值与数组中没有出现的最小值(也就是a)异或,假如得到的值等于k,那么ans=n+2,否则ans=n+1 #include <bits/

vv的博客 305

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

Codeforces Round #742 (Div. 2)「B」「C」「D」妙妙场

Codeforces Round #742 (Div. 2) B. MEXor Mixup 题目描述: 输入a和b,让你造一个数组,使得这个数组内所有数异或和为b,且这个数组中未出现的最小的非负数是a 思路: 因为最小非负数是a,也就是说最少要用a-1个数,且a是不可用的 我们可以维护一个前缀异或和为tr[i],表示从0异或到i的值 如果tr[a - 1] = b,就说明用0到a-1就可以了,输出a即可 如果tr[a - 1] ^b = a,就说明要将tr[a - 1]异或上a才能变成b,但是由于a

Suryxin's blogs 184

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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 solution time limit per test 1 second memory limit per test 256 megabytes input standa

Shyazhut 732

【codeforces 742B】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...

92

Codeforces Round #742 (Div. 2) B、C 题解

Codeforces Round 742 B. MEXor Mixup 题意 有一个数组,输入两个数a,b,a代表这个数组之外的最小非负整数,b代表这个数组的异或值,问你该数组的最小长度。 思路 首先,a保证了数组至少是由0 ~(a-1) 这些数组成,设0 ~(a-1) 的异或值为x 1.如果x==b,则该数组的最小长度为a 2.如果x!=b,且x^b!=a,此时数组之外的最小非负整数仍为a,又**因为 x^x=0, 0^b=b, abc=a(bc),**所以在原数组加上一个 **xb,xx^b=b,**此

Tr13660577247的博客 282

CodeForces 742B 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 per test 256 megabytes input standard input output standard output There are so

Sirius_han的博客 342

Arpa’s obvious problem and Mehrdad’s terrible solution codeforces problem/742/ 异或

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

FOWng_lp的博客 277

Codeforces Round #742 (Div. 2) B,C,D,E

B. MEXor Mixup 题意: 给定2个数a,b,然后构造一个非负数组,使得这个数组满足 1.对这个数组做Mex操作,结果为a 2.对所有元素做XOR结果为b 问这个数组的长度最少是多少? 思路: 首先从2个条件出发 1.Mex(array) == a 那么代表着0 ~ a - 1这些数是必须在数组里面的,个数为a 2.XOR(array) == b 由第一个条件知道数组中肯定有0 ~ a - 1 设 x = 0 ^ 1 ^ … ^ a - 1 再设数组中还需要添加的数他们的XOR值为y 那么 x ^

weixin_54618249的博客 197

Codeforces Round #383 (Div. 2) && Codeforces 742 B (标记技巧)

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 standard output Th

K键盘里的青春K 682

codeforces 742B Arpa's obvious problem(水)

点击打开链接 //题意:求ai^aj=x 的(i,j)&&i /两边同^ai   ->   aj=x^ai 枚举i用map统计aj=x^ai出现次数即可  //坑点ans爆int 1e5 x=3 1 2 1 2.......答案约等于1/2(1e5*1e5) 统计出来的ij的个数一一对应,则i>j个数也为k #include #include #include #in

Masamiiiiii 410

CodeForces - 742B Arpa’s obvious problem and Mehrdad’s terrible solution

点击打开链接 求有多少对数相互异或后等于x。 已知 a[i]^a[j]=x   ( i so:   a[j]^x=a[i];      用一个标记数组,(桶计数)   然后每输入一个a[i].加上b[a[i]^x];   并且把b[a[i]]+1; 还有,要用ll #include #define ll long long const int maxn=10

zoro_n的博客 597

CodeForces - 742B Arpa’s obvious problem and Mehrdad’s terrible solution (位运算)

题目链接:http://codeforces.com/problemset/problem/742/B点击打开链接 B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit per test 256 megabytes

xuejye的博客 430
上一篇: poj 1990
下一篇: 最小生成树四种方法概括
黑码
博客等级 码龄10年 76粉丝 454原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值