QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#85654#5665. AA Country and King DreamoonupsolveupsolveRE 2ms3436kbC++203.2kb2023-03-08 00:18:542023-03-08 00:19:13

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-08 00:19:13]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3436kb
  • [2023-03-08 00:18:54]
  • 提交

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),ne(N,-1);
        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();
            }
        }
        
        vector<int> ST2;
        for(int i=si(A)-1;i>r;i--){
            if(si(ST2)<=1||ST2[si(ST2)-2]!=A[i]){
                if(si(ST2)){
                    ne[ST2.back()]=A[i];
                }//par[A[i]]=ST.back();
                ST2.push_back(A[i]);
            }else{
                ST2.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]==INF&&mada.back()==INF){
                A[i]=ne[now];
                ST.push_back(A[i]);
            }else 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: 3436kb

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: