QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#85641#5665. AA Country and King DreamoonupsolveupsolveRE 2ms3460kbC++202.7kb2023-03-07 23:50:332023-03-07 23:50:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 23:50:37]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3460kb
  • [2023-03-07 23:50:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        vector<int> A(2*N-1);
        for(int i=0;i<2*N-1;i++){
            int x;cin>>x;x--;
            A[i]=x;
        }
        if(A.front()==-1) A.front()=0;
        if(A.back()==-1) A.back()=0;
        
        int l=INF,r=-INF;
        for(int i=0;i<2*N-1;i++){
            if(A[i]==-1){
                chmin(l,i);
                chmax(r,i);
            }
        }
        
        if(l==INF){
            for(int a:A) cout<<a+1<<" ";
            cout<<"\n";
            continue;
        }
        
        vector<int> par(N,INF),ST,deta(N);
        for(int i=0;i<l;i++){
            if(si(ST)<=1||ST[si(ST)-2]!=A[i]){
                if(si(ST)) par[A[i]]=ST.back();
                ST.push_back(A[i]);
            }else{
                ST.pop_back();
            }
        }
        
        for(int i=0;i<l;i++){
            deta[A[i]]=1;
        }
        
        for(int i=r+1;i<si(A);i++){
            deta[A[i]]=2;
        }
        
        vector<int> mada;
        
        mada.push_back(INF);
        
        for(int i=N-1;i>=0;i--){
            if(!deta[i]) mada.push_back(i);
        }
        /*
        for(int x:mada) cout<<x<<" ";
        cout<<endl;
        for(int a:ST) cout<<a<<" ";
        cout<<endl;
        for(int i=0;i<N;i++) cout<<par[i]<<" "<<deta[i]<<endl;
        */
        for(int i=l;i<=r;i++){
            int now=ST.back();
            if(par[now]>mada.back()){
                int ne=mada.back();
                mada.pop_back();
                par[ne]=now;
                ST.push_back(ne);
                A[i]=ne;
            }else{
                if(deta[now]==2){
                    int ne=mada.back();
                    mada.pop_back();
                    par[ne]=now;
                    ST.push_back(ne);
                    A[i]=ne;
                }else{
                    ST.pop_back();
                    A[i]=ST.back();
                }
                
            }
        }
        
        for(int a:A) cout<<a+1<<" ";
        cout<<"\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3460kb

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: -100
Runtime Error

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:


result: