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;
const int N = 1005;
// int a[N], L[N], R[N];
int par[N];
// int get(int l, int r) {
// 	int gcd = 0;
// 	for (int i = l; i <= r; ++i) gcd = __gcd(gcd, a[i]);
// 	return gcd;
// }
// int query(int a, int b, int c, int d) {
// 	return get(a, b) == get(c, d);
// }
int solve(int n, int* L, int* R) {
	memset(par, -1, sizeof par);
	L[0] = R[0] = -1;
	for (int i = 1; i < n; ++i) {
		int cur = i - 1;
		L[i] = R[i] = -1;
		while (1) {
			if (query(cur, i, i, i)) {
				if (par[cur] == -1) {
					par[cur] = i, L[i] = cur; break;
				}
				else cur = par[cur];
			}
			else {
				if (R[cur] == -1) R[cur] = i, par[i] = cur;
				else par[R[cur]] = i, par[i] = cur, L[i] = R[cur], R[cur] = i;
				break;
			}
		}
	}
	int root = 0;
	for (int i = 0; i < n; ++i) if (par[i] == -1) root = i;
	return root;
}
// int main() {
// 	int n; cin >> n;
// 	for (int i = 0; i < n; ++i) cin >> a[i];
// 	solve(n, L, R);
// 	for (int i = 0; i < n; ++i) cout << L[i] << ' '; cout << '\n';
// 	for (int i = 0; i < n; ++i) cout << R[i] << ' '; cout << '\n';
// }
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |