题解 CF742B Arpa’s obvious problem and Mehrdad’s terrible solution

思路

题目要求对于 i,j\forall i,j 有多少个 aiaj=xa_i\oplus a_j=x

那么我们需要知道异或最重要的一个性质:

ab=cac=ba\oplus b=c\Rightarrow a\oplus c=b

那么每输入一个数字,我们可以判断与前面输入过的数字是否满足 aiaj=xa_i\oplus a_j=x 即可。若满足则 sum+=a[t^x] 即可。注意开 long long 哦。

AC 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
ll n,x,t,a[100005]={0},sum=0;
cin >> n >> x;
for(int i=1;i<=n;i++){
cin >> t;
sum += a[t^x];
a[t]++;
}
cout << sum;
return 0;
}

题解 CF742B Arpa’s obvious problem and Mehrdad’s terrible solution
https://sunnyli.咕咕咕.eu.org/solution-CF742B/
作者
SunnyLi
发布于
2023年6月15日
许可协议