当前位置:   article > 正文

A Xor B Problem(异或)---2023年天梯赛(GPLT)上海理工大学校内选拔赛-A

a xor b problem

在这里插入图片描述

解析

异或相等,即为两数相等,统计累计答案即可

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
const int mod=1e9+7;
const int N=2e5+5;
int n,m;
int a[N];
map<int,int>mp;
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	int ans=n;
	for(auto it:mp){
		int t=it.second;
		ans+=t*(t-1);
	}
	cout<<ans;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt=1;
//	cin>>t;
	while(tt--) solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/796478
推荐阅读
相关标签
  

闽ICP备14008679号