bzoj 2761: [JLOI2011]不重复数字【hash】
map会T,双hash会冲突……于是非酋写了个三hash
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1000005,mod1=739391,mod2=967543,mod3=1000003;
int T,n;
bool h1[N],h2[N],h3[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
T=read();
while(T--)
{
n=read();
memset(h1,0,sizeof(h1));
memset(h2,0,sizeof(h2));
memset(h3,0,sizeof(h3));
for(int i=1;i<=n;i++)
{
int x=read(),x1=(x%mod1+mod1)%mod1,x2=(x%mod2+mod2)%mod2,x3=(x%mod3+mod3)%mod3;
if(!h1[x1]||!h2[x2]||!h3[x3])
{
h1[x1]=1,h2[x2]=1,h3[x3]=1;
printf("%d ",x);
}
}
puts("");
}
return 0;
}