This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "popa.h"
#include <iostream>
#include <vector>
using namespace std;
int solve(int n, int Lson[], int Rson[]){
    for(int i=0; i<n; i++) Lson[i]=Rson[i]=-1;
    vector<int> S; S.push_back(0);
    for(int i=1; i<n; i++){
        // for(int x:S) cout<<x<<' ';
        // cout<<'\n';
        if(query(i,i,S.back(),i)){
            vector<int> V;
            V.push_back(S.back()); S.pop_back();
            while(!S.empty()){
                int j=S.back();
                if(!query(i,i,j,i)) break;
                V.push_back(j); S.pop_back();
            }
            for(int i=0; i<(int)V.size()-1; i++){
                Rson[V[i+1]]=V[i];
            }
            Lson[i]=V.back();
            S.push_back(i);
        }
        else S.push_back(i);
    }
    for(int sz=S.size(), i=sz-1; i>0; i--){
        Rson[S[i-1]]=S[i];
        S.pop_back();
    }
    // for(int i=0; i<n; i++) cout<<Lson[i]<<' ';
    // cout<<'\n';
    // for(int i=0; i<n; i++) cout<<Rson[i]<<' ';
    // cout<<'\n';
    return S[0];
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |