Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

inline void Cmin(int &a, int b) {
	if (a > b) a = b;
	return;
}

const int N = 200010;

int n;
int a[N], hash[N];

namespace Segment_Tree {

#define lc k << 1
#define rc k << 1 | 1

	struct Node {
		int l, r, Min[2];
	} p[N << 2];

	void Build(int k, int l, int r) {
		p[k].l = l;
		p[k].r = r;
		if (l == r) {
			p[k].Min[l & 1] = a[l];
			p[k].Min[(l & 1) ^ 1] = n + 1;
			return;
		}
		int m = (l + r) >> 1;
		Build(lc, l, m);
		Build(rc, m + 1, r);
		p[k].Min[0] = min(p[lc].Min[0], p[rc].Min[0]);
		p[k].Min[1] = min(p[lc].Min[1], p[rc].Min[1]);
		return;
	}

	int Query(int k, int l, int r, int bit) {
		if (l <= p[k].l && p[k].r <= r) return p[k].Min[bit];
		int Min = n + 1;
		if (l <= p[lc].r) Cmin(Min, Query(lc, l, r, bit));
		if (p[rc].l <= r) Cmin(Min, Query(rc, l, r, bit));
		return Min;
	}

#undef lc
#undef rc

}

struct Node {
	Node (int l = 0, int r = 0, int Min = n + 1) : l(l), r(r), Min(Min) {}
	int l, r, Min;
	bool operator < (const Node &a) const {
		return Min > a.Min;
	}
};

priority_queue<Node> pq;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		hash[a[i]] = i;
	}
	Segment_Tree::Build(1, 1, n);
	pq.push(Node(1, n, Segment_Tree::Query(1, 1, n, 1)));
	for (int i = 1; i <= n && !pq.empty(); i += 2) {
		Node cur = pq.top();
		pq.pop();

#define l cur.l
#define r cur.r
#define Min cur.Min

		int k1 = hash[Min], k2 = hash[Segment_Tree::Query(1, k1, r, (k1 & 1) ^ 1)];
        printf("%d %d ", a[k1], a[k2]);
        if (l < k1) pq.push(Node(l, k1 - 1, Segment_Tree::Query(1, l, k1 - 1, l & 1)));
        if (k1 + 1 < k2) pq.push(Node(k1 + 1, k2 - 1, Segment_Tree::Query(1, k1 + 1, k2 - 1, (k1 + 1) & 1)));
        if (k2 < r) pq.push(Node(k2 + 1, r, Segment_Tree::Query(1, k2 + 1, r, (k2 + 1) & 1)));
        
#undef l
#undef r
#undef Min

	}
	putchar('\n');
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:17: error: reference to 'hash' is ambiguous
   70 |                 hash[a[i]] = i;
      |                 ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:16:11: note:                 'int hash [200010]'
   16 | int a[N], hash[N];
      |           ^~~~
a.cc:82:26: error: reference to 'hash' is ambiguous
   82 |                 int k1 = hash[Min], k2 = hash[Segment_Tree::Query(1, k1, r, (k1 & 1) ^ 1)];
      |                          ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:16:11: note:                 'int hash [200010]'
   16 | int a[N], hash[N];
      |           ^~~~
a.cc:83:35: error: 'k2' was not declared in this scope; did you mean 'k1'?
   83 |         printf("%d %d ", a[k1], a[k2]);
      |                                   ^~
      |                                   k1