题目
题目传送门
题解
- 用
h
a
s
h
hash
hash代替桶排序,判断每个数字是否出现直接输出即可
code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 5e4 + 100;
template <typename T>
inline void read(T &s) {
s = 0;
T w = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
while (isdigit(ch)) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
s *= w;
}
int t, n;
int h[maxn];
const int mod = 100003;
inline int ha(LL x) { return x % mod; }
inline int find(LL x) {
int y = ha(abs(x));
while (h[x] && h[x] != x) ha(++y);
return y;
}
inline void insert(LL x) { h[find(x)] = x; }
inline bool check(LL x) { return h[find(x)] == x; }
int main() {
read(t);
while (t--) {
memset(h, 0, sizeof(h));
read(n);
for (int i = 1; i <= n; ++i) {
int x; read(x);
if (check(x)) continue;
printf("%d ", x);
insert(x);
}
putchar('\n');
}
return 0;
}