在本地测了一下样例,感觉非常amazing,一交就裂开了……
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int T, n;
inline ll read() {
ll k = 0, f = 1;
char ch = getchar();
while ( ch < '0' || ch > '9' ) {
if ( ch == '-' ) f = -1;
ch = getchar();
}
while ( ch >= '0' && ch <= '9' ) {
k = k * 10 + ( ch - '0' );
ch = getchar();
}
return k * f;
}
inline ll write ( ll x ) {
if ( x < 0 ) putchar ( '-' ), x = -x;
if ( x > 9 ) write ( x / 10 );
putchar ( x % 10 + '0' );
}
struct node {
ll number, cont;
} s[500005];
bool cmp1 ( node a, node b ) {
return a.number < b.number;
}
bool cmp2 ( node a, node b ) {
return a.cont < b.cont;
}
int main () {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
cin >> T;
while ( T-- ) {
cin >> n;
//离散化
for ( int i = 1; i <= n; i++ ) {
s[i].number = read(), s[i].cont = i;
}
sort(s+1,s+1+n,cmp1);
for(int i=1;i<=n;i++){
if(s[i].number==s[i-1].number) s[i].cont=9000000;
}
sort(s+1,s+1+n,cmp2);
for(int i=1;i<=n;i++){
if(s[i].cont==9000000) break;
write(s[i].number);putchar(' ');
}
}
return 0;
}