Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP:
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
        //x += y;
        //x = max(x,y);
        //x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        return min(x,y);
        //return x+y;
        //return max(x,y);
    }

public:
    SegmentTree() {}
    
    void init(int sz, T E_) {
        E = E_;
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での値を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};

int n;
vector<int> p;
SegmentTree<P> even, odd;
priority_queue<PP, vector<PP>, greater<PP>> pque;

vector<int> pa;

// void dfs(int l, int r) {
//     if(l + 1 >= r) return;

//     P x, y;
//     if(l % 2 == 0) {
//         x = even.get(l, r);
//         y = odd.get(l, r);
//     } else {
//         x = odd.get(l, r);
//         y = even.get(l, r);
//     }
//     pque.push(make_pair(x.fr, make_pair(l, r)));
//     pa[x.fr] = y.fr;

//     int a = x.sc, b = y.sc;

//     dfs(l, a);
//     dfs(a + 1, b);
//     dfs(b + 1, r);
// }

PP f(int l, int r) {
    P x;
    if(l % 2 == 0) {
        x = even.get(l, r);
    } else {
        x = odd.get(l, r);
    }
    return make_pair(x.fr, make_pair(l, r));
}

void solve() {
	cin >> n;
    p.resize(n);
    pa.resize(n); 
    rep(i, n) {
        cin >> p[i];
    }
    even.init(n, make_pair(INF, INF));
    odd.init(n, make_pair(INF, INF));
    rep(i, n) {
        if(i % 2 == 0) {
            even.update(i, make_pair(p[i], i));
        } else {
            odd.update(i, make_pair(p[i], i));
        }
    }
    vector<int> ans;
    
    P x, y;
    x = even.get(l, r);
    y = odd.get(l, r);
    pque.push(make_pair(x.fr, make_pair(l, r)));
    pa[x.fr] = y.fr;

    while(!pque.empty()) {
        PP q = pque.top(); pque.pop();
        int a = q.fr;
        ans.push_back(a);
        ans.push_back(pa[a]);

        int l = q.sc.fr, r = q.sc.sc;
        if(l % 2 == 0) {
            x = even.get(l, r);
            y = odd.get(l, r);
        } else {
            x = odd.get(l, r);
            y = even.get(l, r);
        }

        int u = x.sc, v = y.sc;
        if(l + 1 < u) pque.push(f(l, u));
        if(u + 1 < v) pque.push(f(u + 1, v));
        if(v + 1 < r) pque.push(f(v + 1, r));
    }

    rep(i, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Compiler output:
a.cc:41:37: error: expected initializer before ':' token
   41 | typedef pair<int, pair<int, int>> PP:
      |                                     ^
a.cc:119:16: error: 'PP' was not declared in this scope; did you mean 'P'?
  119 | priority_queue<PP, vector<PP>, greater<PP>> pque;
      |                ^~
      |                P
a.cc:119:27: error: 'PP' was not declared in this scope; did you mean 'P'?
  119 | priority_queue<PP, vector<PP>, greater<PP>> pque;
      |                           ^~
      |                           P
a.cc:119:29: error: template argument 1 is invalid
  119 | priority_queue<PP, vector<PP>, greater<PP>> pque;
      |                             ^
a.cc:119:29: error: template argument 2 is invalid
a.cc:119:40: error: 'PP' was not declared in this scope; did you mean 'P'?
  119 | priority_queue<PP, vector<PP>, greater<PP>> pque;
      |                                        ^~
      |                                        P
a.cc:119:40: error: template argument 1 is invalid
a.cc:119:42: error: template argument 1 is invalid
  119 | priority_queue<PP, vector<PP>, greater<PP>> pque;
      |                                          ^~
a.cc:119:42: error: template argument 2 is invalid
a.cc:119:42: error: template argument 3 is invalid
a.cc:144:1: error: 'PP' does not name a type; did you mean 'P'?
  144 | PP f(int l, int r) {
      | ^~
      | P
a.cc: In function 'void solve()':
a.cc:173:18: error: 'l' was not declared in this scope
  173 |     x = even.get(l, r);
      |                  ^
a.cc:173:21: error: 'r' was not declared in this scope
  173 |     x = even.get(l, r);
      |                     ^
a.cc:175:10: error: request for member 'push' in 'pque', which is of non-class type 'int'
  175 |     pque.push(make_pair(x.fr, make_pair(l, r)));
      |          ^~~~
a.cc:178:17: error: request for member 'empty' in 'pque', which is of non-class type 'int'
  178 |     while(!pque.empty()) {
      |                 ^~~~~
a.cc:179:9: error: 'PP' was not declared in this scope; did you mean 'P'?
  179 |         PP q = pque.top(); pque.pop();
      |         ^~
      |         P
a.cc:179:33: error: request for member 'pop' in 'pque', which is of non-class type 'int'
  179 |         PP q = pque.top(); pque.pop();
      |                                 ^~~
a.cc:180:17: error: 'q' was not declared in this scope
  180 |         int a = q.fr;
      |                 ^
a.cc:194:28: error: request for member 'push' in 'pque', which is of non-class type 'int'
  194 |         if(l + 1 < u) pque.push(f(l, u));
      |                            ^~~~
a.cc:194:33: error: 'f' was not declared in this scope
  194 |         if(l + 1 < u) pque.push(f(l, u));
      |                                 ^
a.cc:195:28: error: request for member 'push' in 'pque', which is of non-class type 'int'
  195 |         if(u + 1 < v) pque.push(f(u + 1, v));
      |                            ^~~~
a.cc:195:33: error: 'f' was not declared in this scope
  195 |         if(u + 1 < v) pque.push(f(u + 1, v));
      |                                 ^
a.cc:196:28: error: request for member 'push' in 'pque', which is of non-class type 'int'
  196 |         if(v + 1 < r) pque.push(f(v + 1, r));
      |                            ^~~~
a.cc:196:33: error: 'f' was not declared in this scope
  196 |         if(v + 1 < r) pque.push(f(v + 1, r));
      |                                 ^