@[right_cat](/space/show?uid=76561)
把
```cpp
std::sort(s1 + 1, s1 + n + 1, cmp1);
```
改为
```cpp
std::stable_sort(s1 + 1, s1 + n + 1, cmp1);
```
by Smile_Cindy @ 2019-05-01 17:02:39
@[Alpha](/space/show?uid=87058)
不太会用这个,但如果直接改好像会编译错误。
by right_cat @ 2019-05-01 17:12:37
@[right_cat](/space/show?uid=76561)
完整代码
```cpp
#include <cstdio>
#include <cctype>
#include <algorithm>
const int MAXN = 50000;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-')
f = -1;
ch = getchar();
}
while(isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct Node1 {
int x1, id1;
}s1[MAXN + 5];
struct Node2 {
int x2, id2;
}s2[MAXN + 5];
inline bool cmp1(Node1 a, Node1 b) {
return a.x1 < b.x1;
}
inline bool cmp2(Node2 a, Node2 b) {
return a.id2 < b.id2;
}
int main() {
int t = read();
while(t--) {
int n = read();
for(int i = 1; i <= n; i++) {
s1[i].x1 = read();
s1[i].id1 = i;
}
std::stable_sort(s1 + 1, s1 + n + 1, cmp1);
int tot = 0;
for(int i = n; i >= 1; i--)
if(s1[i].x1 != s1[i - 1].x1) {
s2[++tot].x2 = s1[i].x1;
s2[tot].id2 = s1[i].id1;
}
std::sort(s2 + 1, s2 + tot + 1, cmp2);
for(int i = 1; i < tot; i++)
printf("%d ", s2[i].x2);
printf("%d\n", s2[tot].x2);
}
}
```
by Smile_Cindy @ 2019-05-01 17:14:50
@[Alpha](/space/show?uid=87058)
谢谢,我过了。
by right_cat @ 2019-05-01 17:16:23