P4305 gp_hash_table< , >mp; FastIO
[JLOI2011]不重复数字
题目描述
给定 \(n\) 个数,要求把其中重复的去掉,只保留第一次出现的数。
输入格式
本题有多组数据。
第一行一个整数 \(T\),表示数据组数。
对于每组数据:
第一行一个整数 \(n\)。
第二行 \(n\) 个数,表示给定的数。
输出格式
对于每组数据,输出一行,为去重后剩下的数,两个数之间用一个空格隔开。
样例 #1
样例输入 #1
2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
样例输出 #1
1 2 18 3 19 6 5 4
1 2 3 4 5 6
提示
对于 \(30\%\) 的数据,\(n \le 100\),给出的数 \(\in [0, 100]\)。
对于 \(60\%\) 的数据,\(n \le 10^4\),给出的数 \(\in [0, 10^4]\)。
对于 \(100\%\) 的数据,\(1 \le T\le 50\),\(1 \le n \le 5 \times 10^4\),给出的数在 \(32\) 位有符号整数范围内。
用超级快读可以大大优化速率!!!
map用 gp_hash_table 也快得多!!!
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
//#define int long long
int t,n,x;
namespace FastIO
{
const int _Pu=1<<16;
const int _d=32;
char buf[_Pu];
char *p1=buf+_Pu;
char *p2=buf+_Pu;
inline void flushin(){
memmove(buf,p1,p2-p1);
int rlen=fread(buf+(p2-p1),1,p1-buf,stdin);
if(p1-rlen>buf){buf[p2-p1+rlen]='\0';}
p1=buf;
}
template<typename T>inline void read(T& x)
{
if(p1>p2-_d){flushin();}
int isne = 0;
for (;!isdigit(*p1);++p1){isne=(*p1=='-');}
x=(*p1++-'0');
for (;isdigit(*p1);++p1){x=x*10+(*p1-'0');}
if(isne){x=-x;}
}
char obuf[_Pu];
char *p3=obuf,*p4=obuf+_Pu-_d;
inline void flushout(){fwrite(obuf,p3-obuf,1,stdout),p3=obuf;}
template<typename T>inline void write(T x, char end = '\n')
{
if(p3>p4){flushout();}
if(x<0){*p3++='-';x=-x;}
char sta[20];char *top=sta;
do{*top++=(x%10)+'0';x/=10;}while(x);
do{*p3++=*--top;}while(top!=sta);
(*p3++)=end;
}
void unsafepc(char x){
*p3++=x;
}
}
using namespace FastIO;
signed main()
{
read(t);
while(t--)
{
gp_hash_table<int,bool>mp;
read(n);
for(int i=1;i<=n;i++)
{
read(x);
if(!mp[x])
{
write(x,' ');
mp[x]=1;
}
}
unsafepc('\n');
}
flushout();
return 0;
}

浙公网安备 33010602011771号