loj6537. 毒瘤题加强版再加强版

题面

题意:对于一个\(n\)个数的可重集,求出所有\(k\)个出现次数为奇数的数\(a\)

\(n \leq 3\times 10^6,k \leq 5000\),memory limit=3MiB。

题解:显然无法开下长为\(n\)的数组。那么考虑用哈希表进行压缩。也就是给每个数一个\(key,value\)

考虑如何统计出现次数为奇数。可以找到\(key\)值后进行异或操作,异或一个\(value\)

考虑存在哈希冲突,那么我们多开几个哈希表就行了。

最后统计时,直接枚举所有哈希表的所有\(key\),找到其对应的\(value\)即可,答案用set存一下就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
const ll INF=998244353,P=2048576;
ll c[7]={0,29131,29947,29663,26399,28151,28669};
int n,m;ll w,v,f[7][30300];
set<int>s;
int main(){
	read(n);read(m);
	while(n--){
		read(w);
		F(i,1,6)v=w*INF+P,f[i][w%c[i]]^=v;
	}
	F(i,1,6)F(j,0,c[i]-1){
		w=f[i][j]/INF;if((f[i][j]%INF)==P&&!s.count(w))s.insert(w);
	}
	for(auto it=s.begin();it!=s.end();it++)cout<<*it<<endl;
	return 0;
}
posted @ 2020-07-09 11:57  Purple_wzy  阅读(231)  评论(0编辑  收藏  举报