Language: C++

#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class ForwardIterator, class T>
bool All_of(ForwardIterator first, ForwardIterator last, const T& value) {
	for (; first < last; ++first) if (*first != value) return false; return true;
}
// all_of

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#include "Segment_Tree.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif


int N;
int A[200000];
SegmentTree<PP> Xmin(100000, PP(INF, -1), Min<PP>());
SegmentTree<PP> Ymin(100000, PP(INF, -1), Min<PP>());

struct Node {
	Node* a;
	Node* b;
	Node* c;
	PP p;
};

Node* Solve(int l, int r) {
	if (l == r) return nullptr;
	
	Node* ret = new Node;
	vector<PP> a, b, c;
	if (l % 2 == 0) {
		PP x = Xmin.Query(l / 2, r / 2);
		int xi = x.second;
		PP y = Ymin.Query(xi / 2, r / 2);
		int yi = y.second;
		ret->p = PP(x.first, y.first);

		ret->a = Solve(l, xi);
		ret->b = Solve(xi + 1, yi);
		ret->c = Solve(yi + 1, r);
	} else {
		PP y = Ymin.Query(l / 2, r / 2);
		int yi = y.second;
		PP x = Xmin.Query(yi / 2 + 1, r / 2 + 1);
		int xi = x.second;
		ret->p = PP(y.first, x.first);

		ret->a= Solve(l, yi);
		ret->b = Solve(yi + 1, xi);
		ret->c = Solve(xi + 1, r);
	}

	return ret;
}

int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> A[i];
	}

	REP(i, 0, N) {
		if (i % 2 == 0) {
			Xmin.Update(i / 2, PP(A[i], i));
		} else {
			Ymin.Update(i / 2, PP(A[i], i));
		}
	}

	vector<PP> ans;

	Node* root = Solve(0, N);
	PriorityQ<pair<PP, Node*>> Q;
	Q.push(make_pair(root->p, root));
	while (!Q.empty()) {
		auto t = Q.top(); Q.pop();
		ans.push_back(t.first);

		Node* p = t.second;
		if (p->a) Q.push(make_pair(p->a->p, p->a));
		if (p->b) Q.push(make_pair(p->b->p, p->b));
		if (p->c) Q.push(make_pair(p->c->p, p->c));
	}
	REP(i, 0, ans.size()) {
		cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
	}
	return 0;
}


Compiler output:
a.cc:93:1: error: 'SegmentTree' does not name a type
   93 | SegmentTree<PP> Xmin(100000, PP(INF, -1), Min<PP>());
      | ^~~~~~~~~~~
a.cc:94:1: error: 'SegmentTree' does not name a type
   94 | SegmentTree<PP> Ymin(100000, PP(INF, -1), Min<PP>());
      | ^~~~~~~~~~~
a.cc: In function 'Node* Solve(int, int)':
a.cc:109:24: error: 'Xmin' was not declared in this scope; did you mean 'fmin'?
  109 |                 PP x = Xmin.Query(l / 2, r / 2);
      |                        ^~~~
      |                        fmin
a.cc:111:24: error: 'Ymin' was not declared in this scope; did you mean 'fmin'?
  111 |                 PP y = Ymin.Query(xi / 2, r / 2);
      |                        ^~~~
      |                        fmin
a.cc:119:24: error: 'Ymin' was not declared in this scope; did you mean 'fmin'?
  119 |                 PP y = Ymin.Query(l / 2, r / 2);
      |                        ^~~~
      |                        fmin
a.cc:121:24: error: 'Xmin' was not declared in this scope; did you mean 'fmin'?
  121 |                 PP x = Xmin.Query(yi / 2 + 1, r / 2 + 1);
      |                        ^~~~
      |                        fmin
a.cc: In function 'int main()':
a.cc:141:25: error: 'Xmin' was not declared in this scope; did you mean 'fmin'?
  141 |                         Xmin.Update(i / 2, PP(A[i], i));
      |                         ^~~~
      |                         fmin
a.cc:143:25: error: 'Ymin' was not declared in this scope; did you mean 'fmin'?
  143 |                         Ymin.Update(i / 2, PP(A[i], i));
      |                         ^~~~
      |                         fmin