水题= =离散就好了= =
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; const int maxn = 100010; int n, a[maxn]; int pos[maxn], T, v[maxn], num = 0; bool cmp(int x, int y) { return a[x] < a[y]; } bool vis[maxn]; int ans[maxn]; int len = 0; void sov() { scanf("%d", &T); while(T --) { scanf("%d", &n); memset(vis, 0, sizeof(vis)); num = 0; for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]); for(int i = 1; i <= n; ++ i) pos[i] = i; sort(pos + 1, pos + 1 + n, cmp); a[pos[0]] = a[pos[1]] - 1; for(int i = 1; i <= n; ++ i) { if(a[pos[i]] != a[pos[i - 1]]) num ++; v[pos[i]] = num; } len = 0; for(int i = 1; i <= n; ++ i) { if(!vis[v[i]]) ans[++ len] = a[i], vis[v[i]] = 1; } for(int i = 1; i < len; ++ i) printf("%d ", ans[i]); printf("%d\n", ans[len]); } } int main() { //freopen("test.in", "r", stdin); sov(); return 0; }