Language: C++

#include <bits/stdc++.h>

using namespace std;
const int N = 200002;
struct node {
    int mn, mx, mnInd, mxInd;
};
int n,arr[N];
node odd[4*N], even[4*N];
vector <vector<pair<int,int> > > vec(N);

void buildOdd(int pos,int l,int r) {
    if(l == r) {
        if(l % 2)
            odd[pos] = node {arr[l],arr[l],l,l};
        else
            odd[pos] = node {1E9,-1E9,n,n+1};
        return;
    }
    int mid = (l+r)/2;
    buildOdd(pos*2,l,mid), buildOdd(pos*2+1,mid+1,r);
    if(odd[pos*2].mn < odd[pos*2+1].mn)
        odd[pos].mn = odd[pos*2].mn, odd[pos].mnInd = odd[pos*2].mnInd;
    else
        odd[pos].mn = odd[pos*2+1].mn, odd[pos].mnInd = odd[pos*2+1].mnInd;
}

void buildEven(int pos,int l,int r) {
    if(l == r) {
        if(l % 2 == 0)
            even[pos] = node {arr[l],arr[l],l,l};
        else
            even[pos] = node {1E9,-1E9,n,n+1};
        return;
    }
    int mid = (l+r)/2;
    buildEven(pos*2,l,mid), buildEven(pos*2+1,mid+1,r);
    if(even[pos*2].mn < even[pos*2+1].mn)
        even[pos].mn = even[pos*2].mn, even[pos].mnInd = even[pos*2].mnInd;
    else
        even[pos].mn = even[pos*2+1].mn, even[pos].mnInd = even[pos*2+1].mnInd;
}

node getOdd(int pos,int l,int r,int qLow,int qHigh) {
    if(l > qHigh || r < qLow || qLow>qHigh)
        return node{1E9,-1E9,n,n+1};
    if(l >= qLow && r <= qHigh)
        return odd[pos];
    int mid = (l+r)/2;
    node ret;
    node lf = getOdd(pos*2,l,mid,qLow,qHigh), ri = getOdd(pos*2+1,mid+1,r,qLow,qHigh);
    if(lf.mn < ri.mn)
        ret = lf;
    else
        ret = ri;
    return ret;
}

node getEven(int pos,int l,int r,int qLow,int qHigh) {
    if(l > qHigh || r < qLow || qLow > qHigh)
        return node{1E9,-1E9,n,n+1};
    if(l >= qLow && r <= qHigh)
        return even[pos];
    int mid = (l+r)/2;
    node ret;
    node lf = getEven(pos*2,l,mid,qLow,qHigh), ri = getEven(pos*2+1,mid+1,r,qLow,qHigh);
    if(lf.mn < ri.mn)
        ret = lf;
    else
        ret = ri;
    return ret;
}

void solve(int l,int r,int curr) {
    if(l > r)
        return;
    node o = getOdd(1,0,n-1,l,r);
    node e = getEven(1,0,n-1,l,r);
    if(o.mnInd <e.mnInd) {
        vec[curr].push_back(make_pair(o.mn,e.mn));
        solve(l,o.mnInd-1,curr+1);
        solve(o.mnInd+1,e.mnInd-1,curr+1);
        solve(e.mnInd+1,r,curr+1);
    } else {
        vec[curr].push_back(make_pair(e.mn,o.mn));
        solve(l,e.mnInd-1,curr+1);
        solve(e.mnInd+1,o.mnInd-1,curr+1);
        solve(o.mnInd+1,r,curr+1);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i = 0;i<n;i++)
        scanf("%d",&arr[i]);
    buildOdd(1,0,n-1);
    buildEven(1,0,n-1);
    solve(0,n-1,0);
    for(int i = 0;i<N;i++)
        sort(vec[i].begin(), vec[i].end());
    for(int i = 0;i<N;i++)
        for(int j = 0;j<vec[i].size();j++)
            printf("%d %d ",vec[i][j].first,vec[i][j].second);

    return 0;
}



Compiler output:
a.cc: In function 'void buildOdd(int, int, int)':
a.cc:17:30: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
   17 |             odd[pos] = node {1E9,-1E9,n,n+1};
      |                              ^~~
a.cc: In function 'void buildEven(int, int, int)':
a.cc:33:31: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
   33 |             even[pos] = node {1E9,-1E9,n,n+1};
      |                               ^~~
a.cc: In function 'node getOdd(int, int, int, int, int)':
a.cc:46:21: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
   46 |         return node{1E9,-1E9,n,n+1};
      |                     ^~~
a.cc: In function 'node getEven(int, int, int, int, int)':
a.cc:61:21: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
   61 |         return node{1E9,-1E9,n,n+1};
      |                     ^~~