QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524532#5665. AA Country and King Dreamoonucup-team3699TL 34ms7832kbC++203.6kb2024-08-19 19:08:392024-08-19 19:08:39

Judging History

你现在查看的是最新测评结果

  • [2024-08-19 19:08:39]
  • 评测
  • 测评结果:TL
  • 用时:34ms
  • 内存:7832kb
  • [2024-08-19 19:08:39]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

// #define int long long
#define pb push_back
#define F first 
#define S second 

const int mol=998244353;
const int N = 3e5+5;

vector<int>node[N];
int a[N*2], lst[N], fa[N];
bool vis[N], vv[N], in[N];
vector<int>un;
int iu=0;
int n;
void dfs(int v, int pre){
    assert(v!=0);
    assert(vv[v]==0);
    vv[v]=1;
    iu++;
    a[iu]=v;
    while(iu<n*2-1&&a[iu+1]){ if(a[iu+1]==pre) return;if(vv[a[iu+1]]) return;  dfs(a[iu+1], v), iu++, a[iu]=v;}
    assert(iu<=n*2-1);
    int nn=-1;
    for(int i: node[v]){
        if(i==pre) continue;
        if(!in[i]&&!vv[i]) nn=i; 
    }
    
    if(v==pre){
        if(un.size()==0&&nn!=-1){
            dfs(nn, v);
            iu++;a[iu]=v;
            return;
        }
        while(un.size()&&un.back()<v) {
            if(nn!=-1&&!vv[nn]&&nn<un.back()) {dfs(nn, v);a[++iu]=v;break;}
            int g=un.back(); un.pop_back();
            dfs(g, v), a[++iu]=v;
        }
        while(un.size()) {
            if(nn!=-1&&!vv[nn]&&nn<un.back()) {dfs(nn, v);a[++iu]=v;break;}
            a[++iu]=un.back(), a[++iu]=v, un.pop_back();
        }
        if(nn!=-1&&!vv[nn]) dfs(nn, v), iu++, a[iu]=v;
        while(iu<n*2-1&&a[iu+1]){ dfs(a[iu+1], v), iu++, a[iu]=v;}
        assert(iu<=n*2-1);
        return;
    }
        while(un.size()&&un.back()<pre){
            if(nn!=-1&&!vv[nn]&&nn<un.back()) {dfs(nn, v);a[++iu]=v;break;}
            if(un.back()<v){
                int g=un.back();
                un.pop_back();
                dfs(g, v), a[++iu]=v ;
            }
            else a[++iu]=un.back(), a[++iu]=v, un.pop_back();
        }
        if(lst[v]>iu){
            
            while(un.size()&&un.back()<v) {
                if(nn!=-1&&!vv[nn]&&nn<un.back()) {dfs(nn, v);a[++iu]=v;break;}
                int g=un.back();un.pop_back();dfs(g, v), a[++iu]=v;
            }
            while(un.size()) {
                if(nn!=-1&&!vv[nn]&&un.back()>nn){
                    dfs(nn, v);
                    iu++;a[iu]=v;
                    break;
                }
                a[++iu]=un.back(), a[++iu]=v, un.pop_back();
            }
            if(nn!=-1&&!vv[nn]) dfs(nn, v), a[++iu]=v;
            assert(iu<=n*2-1);
            while(iu<n*2-1&&a[iu+1]){ if(a[iu+1]==pre) return;dfs(a[iu+1], v), iu++, a[iu]=v;assert(iu<=n*2-1);}
            
            assert(iu<=n*2-1);
        }
        else {
            if(nn!=-1&&!vv[nn]) dfs(nn, v), a[++iu]=v;
        }
}
void d(int v, int pre){
    fa[v]=pre;
    for(int k: node[v]){
        if(k==pre) continue;
        d(k, v);
    }
}

void solve(){
    iu=0;
    cin>>n;

    for(int i=1;i<=n;i++) vis[i]=0, node[i].clear(), vv[i]=0, lst[i]=0, in[i]=0, fa[i]=0;
    un.clear();
    a[n*2]=0;
    for(int i=1;i<=n*2-1;i++){
        cin>>a[i];
        lst[a[i]]=i;
        vis[a[i]]=1;
        if(i>1&&a[i-1]&&a[i]){
            node[a[i-1]].pb(a[i]);
            node[a[i]].pb(a[i-1]);
        }
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]) un.pb(i);
    }
    reverse(un.begin(), un.end());
    int r;
    if(!a[1]&&!a[n*2-1]){
        for(int i=2;i<=n;i++) cout<<"1 "<<i<<" ";
        cout<<"1\n";
        return;
    }
    else r=max(a[1], a[n*2-1]); 
    a[1]=r, a[n*2-1]=r;
    d(r, r);
    for(int i=2;i<=n*2-1;i++){
        if(a[i-1]==fa[a[i]]&&a[i-1]&&a[i]) in[a[i]]=1;
    }
    dfs(r, r);

    for(int i=1;i<=n*2-1;i++) cout<<a[i]<<" ";cout<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5752kb

input:

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

output:

1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1

result:

ok 9 lines

Test #2:

score: 0
Accepted
time: 31ms
memory: 5700kb

input:

28668
2
0 2 1
2
0 0 1
2
0 0 0
2
1 0 1
2
1 0 0
2
1 2 0
3
0 2 1 3 1
3
0 0 1 3 1
3
0 0 0 3 1
3
0 0 0 0 1
3
0 0 0 0 0
3
1 0 1 3 1
3
1 0 0 3 1
3
1 0 0 0 1
3
1 0 0 0 0
3
1 2 0 3 1
3
1 2 0 0 1
3
1 2 0 0 0
3
1 2 1 0 1
3
1 2 1 0 0
3
1 2 1 3 0
3
0 2 3 2 1
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 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 6 5 6 3 4 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2 1 4 7 4 5 4 1 3 1 6 1 
1 2...

result:

ok 23077 lines

Test #11:

score: 0
Accepted
time: 29ms
memory: 5628kb

input:

23077
7
1 2 1 5 4 5 0 5 1 3 7 3 1
7
1 2 1 5 4 5 6 0 1 3 7 3 1
7
1 2 1 5 4 5 6 0 0 3 7 3 1
7
1 2 1 5 4 5 6 0 0 0 7 3 1
7
1 2 1 5 4 5 6 0 0 0 0 3 1
7
1 2 1 5 4 5 6 5 0 3 7 3 1
7
1 2 1 5 4 5 6 5 0 0 7 3 1
7
1 2 1 5 4 5 6 5 0 0 0 3 1
7
1 2 1 5 4 5 6 5 1 0 7 3 1
7
1 2 1 5 4 5 6 5 1 0 0 3 1
7
1 2 1 5 4 5 ...

output:

1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2 1 5 4 5 6 5 1 3 7 3 1 
1 2...

result:

ok 23077 lines

Test #12:

score: 0
Accepted
time: 29ms
memory: 7728kb

input:

23077
7
1 0 0 6 1 5 7 5 1 4 1 3 1
7
1 0 0 0 1 5 7 5 1 4 1 3 1
7
1 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1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2 1 6 7 6 5 4 3 4 5 6 1 
1 2...

result:

ok 23077 lines

Test #14:

score: 0
Accepted
time: 29ms
memory: 7696kb

input:

23077
7
0 0 0 0 0 6 4 7 1 5 1 3 1
7
1 0 1 7 4 6 4 7 1 5 1 3 1
7
1 0 0 7 4 6 4 7 1 5 1 3 1
7
1 0 0 0 4 6 4 7 1 5 1 3 1
7
1 0 0 0 0 6 4 7 1 5 1 3 1
7
1 2 0 7 4 6 4 7 1 5 1 3 1
7
1 2 0 0 4 6 4 7 1 5 1 3 1
7
1 2 0 0 0 6 4 7 1 5 1 3 1
7
1 2 1 0 4 6 4 7 1 5 1 3 1
7
1 2 1 0 0 6 4 7 1 5 1 3 1
7
1 2 1 7 0 6 ...

output:

1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2 1 7 4 6 4 7 1 5 1 3 1 
1 2...

result:

ok 23077 lines

Test #15:

score: 0
Accepted
time: 30ms
memory: 7748kb

input:

23077
7
1 2 3 2 4 0 5 2 7 2 1 6 1
7
1 2 3 2 4 0 0 2 7 2 1 6 1
7
1 2 3 2 4 0 0 0 7 2 1 6 1
7
1 2 3 2 4 0 0 0 0 2 1 6 1
7
1 2 3 2 4 2 0 2 7 2 1 6 1
7
1 2 3 2 4 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7 6 7 5 7 4 7 2 1 
1 2 3 2 7 6 7 5 7 4 7 2 1 
1 2 3 2 7 6 7 5 7 4 7 2 1 
1 2...

result:

ok 23077 lines

Test #17:

score: 0
Accepted
time: 34ms
memory: 5780kb

input:

23077
7
1 2 3 6 0 0 0 7 5 2 4 2 1
7
1 2 3 6 0 0 0 0 5 2 4 2 1
7
1 2 3 6 3 0 5 7 5 2 4 2 1
7
1 2 3 6 3 0 0 7 5 2 4 2 1
7
1 2 3 6 3 0 0 0 5 2 4 2 1
7
1 2 3 6 3 2 0 7 5 2 4 2 1
7
1 2 3 6 3 2 0 0 5 2 4 2 1
7
1 2 3 6 3 2 5 0 5 2 4 2 1
7
1 2 3 6 3 2 5 7 0 2 4 2 1
7
1 2 3 6 3 2 5 7 0 0 4 2 1
7
1 2 3 6 3 2 ...

output:

1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 5 2 4 2 1 
1 2 3 6 3 2 5 7 4 7 5 2 1 
1 2...

result:

ok 23077 lines

Test #18:

score: 0
Accepted
time: 30ms
memory: 7672kb

input:

23077
7
1 2 4 2 1 6 3 6 7 6 0 6 1
7
1 2 4 2 1 6 3 6 7 6 5 0 1
7
1 2 4 2 1 6 3 6 7 6 5 0 0
7
1 2 4 2 1 6 3 6 7 6 5 6 0
7
0 2 4 2 1 6 3 6 7 5 7 6 1
7
0 0 4 2 1 6 3 6 7 5 7 6 1
7
0 0 0 2 1 6 3 6 7 5 7 6 1
7
1 0 4 2 1 6 3 6 7 5 7 6 1
7
1 0 0 2 1 6 3 6 7 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 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 4 7 4 1 
1 2 5 2 1 4 6 4 3 7 3 4 1 
1 2 5 2 1 4 6 4 3 7 3 4 1 
1 2 5 2 1 4 6 4 3 7 3 4 1 
1 2 5 2 1 4 6 4 3 7 3 4 1 
1 2...

result:

ok 23077 lines

Test #22:

score: 0
Accepted
time: 26ms
memory: 7740kb

input:

23077
7
1 2 0 2 7 2 3 6 4 6 3 2 1
7
1 2 0 0 7 2 3 6 4 6 3 2 1
7
1 2 0 0 0 2 3 6 4 6 3 2 1
7
1 2 5 0 7 2 3 6 4 6 3 2 1
7
1 2 5 0 0 2 3 6 4 6 3 2 1
7
1 2 5 2 0 2 3 6 4 6 3 2 1
7
1 2 5 2 7 0 3 6 4 6 3 2 1
7
1 2 5 2 7 0 0 6 4 6 3 2 1
7
1 2 5 2 7 0 0 0 4 6 3 2 1
7
1 2 5 2 7 2 0 6 4 6 3 2 1
7
1 2 5 2 7 2 ...

output:

1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2 5 2 7 2 3 6 4 6 3 2 1 
1 2...

result:

ok 23077 lines

Test #23:

score: 0
Accepted
time: 27ms
memory: 7832kb

input:

23077
7
1 2 5 6 5 2 1 4 7 0 0 3 1
7
1 2 5 6 5 2 1 4 7 0 0 0 1
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3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2 6 2 1 4 7 4 3 5 3 4 1 
1 2...

result:

ok 23077 lines

Test #25:

score: 0
Accepted
time: 26ms
memory: 5700kb

input:

23077
7
1 2 6 2 7 3 4 3 5 3 7 0 0
7
1 2 6 2 7 3 4 3 5 3 7 2 0
7
0 2 6 2 7 3 4 5 4 3 7 2 1
7
0 0 6 2 7 3 4 5 4 3 7 2 1
7
0 0 0 2 7 3 4 5 4 3 7 2 1
7
0 0 0 0 7 3 4 5 4 3 7 2 1
7
0 0 0 0 0 3 4 5 4 3 7 2 1
7
0 0 0 0 0 0 4 5 4 3 7 2 1
7
0 0 0 0 0 0 0 5 4 3 7 2 1
7
1 0 6 2 7 3 4 5 4 3 7 2 1
7
1 0 0 2 7 3 ...

output:

1 2 6 2 7 3 4 3 5 3 7 2 1 
1 2 6 2 7 3 4 3 5 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2 6 2 7 3 4 5 4 3 7 2 1 
1 2...

result:

ok 23077 lines

Test #26:

score: 0
Accepted
time: 30ms
memory: 5704kb

input:

23077
7
1 2 6 5 6 3 6 4 7 0 0 2 1
7
1 2 6 5 6 3 6 4 7 0 0 0 1
7
1 2 6 5 6 3 6 4 7 0 0 0 0
7
1 2 6 5 6 3 6 4 7 4 0 2 1
7
1 2 6 5 6 3 6 4 7 4 0 0 1
7
1 2 6 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