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 <bits/stdc++.h>
#include "popa.h"
using namespace std;
int solve(int n, int* left, int* right) {
	vector<int> st;
	int root = -1;
	for (int i = 0; i < n; i++) {
		left[i] = right[i] = -1;
		while (st.size() && query(st.back(), i, i, i)) {
			right[st.back()] = left[i];
			left[i] = st.back();
			st.pop_back();
		}
		if (st.size()) right[st.back()] = i;
		else root = i;
		st.push_back(i);
	}
	return root;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |