比赛 2025.9.13 评测结果 AAAAAAAAAAAAAAAAAA
题目名称 The Best Lineup 最终得分 100
用户昵称 健康铀 运行时间 2.465 s
代码语言 C++ 内存使用 4.56 MiB
提交时间 2025-09-13 10:30:01
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;

const int N=200005;

struct Node{
    int pos,v;
};

bool cmp(const Node& a, const Node& b){
    if(a.v!=b.v)return a.v>b.v;
    return a.pos<b.pos;
}

void rd(Node a[], int& n){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i].v;
        a[i].pos=i;
    }
}

void pr(Node a[], int n){
    sort(a+1,a+n+1,cmp);
    int now=0,lst=0;
    bool flag=0;
    for(int i=1;i<=n;++i){
        if(a[i].pos>now){
            lst=now;
            now=a[i].pos;
            cout<<a[i].v<<" ";
        }else if(!flag&&lst<a[i].pos){
            flag=1;
            now=a[i].pos;
            cout<<a[i].v<<" ";
        }
    }
    cout<<"\n";
}

void sol(){
    Node a[N];
    int n;
    rd(a,n);
    pr(a,n);
}

int main(){
	freopen("Lineup.in","r",stdin);
	freopen("Lineup.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;cin>>t;
    while(t--)sol();
    return 0;
}