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

2023-12-06 09:18

本文主要是介绍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 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.

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.

二分搜索

AC代码:

 

# include <stdio.h>
# include <vector>
using namespace std;
typedef long long int ll;
int a[100010];
vector<int> vec[100010];
int main(){int i, j, k, x, n, temp, s;scanf("%d%d", &n, &x);for(i=1; i<=n; i++){scanf("%d", &a[i]);vec[a[i]].push_back(i);}ll ans=0;for(i=1; i<n; i++){temp=x^a[i];if(temp<100010)s=vec[temp].size();elsecontinue;if(s>0){int it=lower_bound(vec[temp].begin(), vec[temp].end(), i+1)-vec[temp].begin();if(it>s)continue;if(it!=s){ans=ans+s-it;}}}printf("%I64d", ans);return 0;
}
 

 

这篇关于codeforces 742B - Arpa’s obvious problem and Mehrdad’s terrible solution的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/461296

相关文章

Codeforces 158B

很久没有刷题了,刚刚有小学弟问了这道题,AC之后贴上来吧。水~~~ #include <cstdio>#include <cmath>int main() {int n;while(scanf("%d", &n) != EOF) {int a = 0, b = 0, c = 0, d = 0;int arr[100001];for (int i = 0; i < n; ++

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

Codeforces April Fools Day Contest 2013

2013年愚人节的坑题。。。 A. Mysterious strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Input The input contains a sin

约瑟夫问题(Josephus Problem)4:第k个出列的人是谁

版权所有。所有权利保留。 欢迎转载,转载时请注明出处: http://blog.csdn.net/xiaofei_it/article/details/16813419 本文是论述约瑟夫问题的第四部分,约瑟夫问题的描述在第一部分,本文用到了第三部分的算法。请先阅读第一部分和第三部分。 现在要求输出第k个出列的人的编号。 由第三部分的算法分析可知,规模为i-1的队列的任意一人的编号为p,规

约瑟夫问题(Josephus Problem)3:谁最后一个出列

版权所有。所有权利保留。 欢迎转载,转载时请注明出处: http://blog.csdn.net/xiaofei_it/article/details/16813349 本文是论述约瑟夫问题的第三部分,约瑟夫问题的描述在第一部分。请先阅读第一部分。 现在要求输出最后一个出列的人的编号。 第一次见到这个问题是在我高一的时候,那时候搞NOIP,培训的时候碰到了这个题目,当时没想到好的方法,

装箱(背包)问题(Packing Problem)

装箱问题也叫背包问题,简单来说,就是把小货物往大箱子里装,要如何才能装得多。个人常见的经历就是“装冰箱”,很有趣的现象就是常常感觉冰箱再也装不下了,但是经过一翻折腾之后又神奇的装下了。   从企业运作角度来看就是尽量让每个容器(仓库、车辆、集装箱、船等)装的尽量多,可以节约企业的费用。通常,装载率85%左右,使用装箱优化方法后,可以达到90~95%左右。海尔做过一个海运装箱的项目,节约了大量运

[Codeforces 451B] Sort the Array (实现)

Codeforces - 451B 给定一个序列,其中每个数都不相同 问是否能在翻转其中一段后,整个序列变得单调递增 实现题 首先设一个 B B数组为 AA数组排序后的结果 由于只能翻转一个区间,那么我假装 A是满足要求的 找到最小的 A[l]≠B[l] A[l] \ne B[l],最大的 A[r]≠B[r] A[r] \ne B[r], 翻转的区间将会是 [l,r

[Codeforces 451A] Game With Sticks (博弈)

Codeforces - 451A N根横向木棍,M根纵向木棍组成了一个网格图 每次可以选择一个交点,去掉所有通过这个交点的木棍 两个人交替进行这个游戏,问最后谁能胜利 每次选择的一个交点,必然去掉了一根横向木棍和纵向木棍 所以每次 N和 M都减一 当其中有一个为 0的时候,就是先手必败态 所以只和 N、M中较小的那个的奇偶性有关 #pragma comment(link

[HDU 5572] An Easy Physics Problem (点在线上判定+对称)

HDU - 5572 给定一个圆和圆外两个点 A和 B 现在有一个质点在 A处,有速度方向 V 其与圆的碰撞是弹性碰撞,问质点是否能经过 B 分情况讨论 如果射线不与圆相交,直接判定点是否在射线上如果射线与圆相交,那么列方程解出与原交点 并得出反弹的法线方程,然后以法线方程作对称 最后判断点是否在一条线段和一条射线上 作对称的话可以将点 A以法线作对称,然后再用撞击点和对

[Codeforces 166B] Polygons (点在凸多边形内)

Codeforces - 166B 判断任意多边形 B是否严格在凸多边形 A内部 点在凸多边形内部试板题 如果 B的所有顶点在 A内,则 B在 A内 由于 A的顶点有 105 10^5个,B的顶点有 104 10^4 个 所以不能用 (n) \mathcal{O}(n)的暴力判断 有一个 (logn) \mathcal{O}(logn) 的二分做法 基本原理是用