Language: C++

#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
int MOD=1000000000+7;
int INF=1e6;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
 
int a[270000];
 
struct sect{
    int first;
    int last;
    int min;
  	
};
bool operator> (const section &s1,const section &s2){
    return s1.min>s2.min;
};
 
 
int d1[270000],d2[270000];
priority_queue<section,vector<section>,greater<section>> p;
 
int search1(int first,int last,int k,int l,int r){
    if(r<first||l>last) return INF;
    if(first<=l&&last>=r) return d1[k];
    int leftmin=search1(first,last,k*2+1,l,(l+r)/2);
    int rightmin=search1(first,last,k*2+2,(l+r+1)/2,r);
    return min(leftmin,rightmin);
}
int search2(int first,int last,int k,int l,int r){
    if(r<first||l>last) return INF;
    if(first<=l&&last>=r) return d2[k];
    int leftmin=search2(first,last,k*2+1,l,(l+r)/2);
    int rightmin=search2(first,last,k*2+2,(l+r+1)/2,r);
    return min(leftmin,rightmin);
}
int n,sup;
int pos[210000];
void GO(){
    while(!p.empty()){
        sect s=p.top();
        p.pop();
        int min2;
        if(pos[s.min]%2){
            min2=search2(pos[s.min]+1,s.last,0,0,sup-1);
        }
        else{
            min2=search1(pos[s.min]+1,s.last,0,0,sup-1);
        }
      	sect t;
        if(s.first!=pos[s.min]){
            if(s.first%2) 
            t={s.first,pos[s.min]-1,search1(s.first,pos[s.min]-1,0,0,sup-1)};
            else
            t={s.first,pos[s.min]-1,search2(s.first,pos[s.min]-1,0,0,sup-1)};
            p.push(t);
        }
        if(pos[s.min]+1!=pos[min2]){
            if(pos[s.min]%2)
            t={pos[s.min]+1,pos[min2]-1,search2(pos[s.min]+1,pos[min2]-1,0,0,sup-1)};
            else
            t={pos[s.min]+1,pos[min2]-1,search1(pos[s.min]+1,pos[min2]-1,0,0,sup-1)};
            p.push(t);
        }
        if(pos[min2]!=s.last){
            if(pos[min2]%2)
            t={pos[min2]+1,s.last,search2(pos[min2]+1,s.last,0,0,sup-1)};
            else
            t={pos[min2]+1,s.last,search1(pos[min2]+1,s.last,0,0,sup-1)};
            p.push(t);
        }
        printf("%d %d ",s.min,min2);
    }
}
main(){
    cin>>n;
    sup=1;
    while(sup<n)
    sup*=2;
    rep(i,n){
        scanf("%d",&a[i]);
        pos[a[i]]=i;
        if(i%2){
            d1[sup-1+i]=a[i];
            d2[sup-1+i]=INF;
        }
        else{
            d2[sup-1+i]=a[i];
            d1[sup-1+i]=INF;
        }
    }
    rep2(i,n,sup){
        d1[sup-1+i]=d2[sup-1+i]=INF;
    }
    for(int i=sup-2;i>=0;i--){
        d1[i]=min(d1[i*2+1],d1[i*2+2]);
        d2[i]=min(d2[i*2+1],d2[i*2+2]);
    }
    sect temp{0,n-1,d2[0]};
  	p.push(temp);
    GO();
    return 0;
}

Compiler output:
a.cc:19:23: error: 'section' does not name a type; did you mean 'sigaction'?
   19 | bool operator> (const section &s1,const section &s2){
      |                       ^~~~~~~
      |                       sigaction
a.cc:19:41: error: 'section' does not name a type; did you mean 'sigaction'?
   19 | bool operator> (const section &s1,const section &s2){
      |                                         ^~~~~~~
      |                                         sigaction
a.cc:19:6: error: 'bool operator>(const int&, const int&)' must have an argument of class or enumerated type
   19 | bool operator> (const section &s1,const section &s2){
      |      ^~~~~~~~
a.cc:25:16: error: 'section' was not declared in this scope; did you mean 'sigaction'?
   25 | priority_queue<section,vector<section>,greater<section>> p;
      |                ^~~~~~~
      |                sigaction
a.cc:25:31: error: 'section' was not declared in this scope; did you mean 'sigaction'?
   25 | priority_queue<section,vector<section>,greater<section>> p;
      |                               ^~~~~~~
      |                               sigaction
a.cc:25:38: error: template argument 1 is invalid
   25 | priority_queue<section,vector<section>,greater<section>> p;
      |                                      ^
a.cc:25:38: error: template argument 2 is invalid
a.cc:25:48: error: 'section' was not declared in this scope; did you mean 'sigaction'?
   25 | priority_queue<section,vector<section>,greater<section>> p;
      |                                                ^~~~~~~
      |                                                sigaction
a.cc:25:48: error: template argument 1 is invalid
a.cc:25:55: error: template argument 1 is invalid
   25 | priority_queue<section,vector<section>,greater<section>> p;
      |                                                       ^~
a.cc:25:55: error: template argument 2 is invalid
a.cc:25:55: error: template argument 3 is invalid
a.cc: In function 'void GO()':
a.cc:44:14: error: request for member 'empty' in 'p', which is of non-class type 'int'
   44 |     while(!p.empty()){
      |              ^~~~~
a.cc:45:18: error: request for member 'top' in 'p', which is of non-class type 'int'
   45 |         sect s=p.top();
      |                  ^~~
a.cc:46:11: error: request for member 'pop' in 'p', which is of non-class type 'int'
   46 |         p.pop();
      |           ^~~
a.cc:60:15: error: request for member 'push' in 'p', which is of non-class type 'int'
   60 |             p.push(t);
      |               ^~~~
a.cc:67:15: error: request for member 'push' in 'p', which is of non-class type 'int'
   67 |             p.push(t);
      |               ^~~~
a.cc:74:15: error: request for member 'push' in 'p', which is of non-class type 'int'
   74 |             p.push(t);
      |               ^~~~
a.cc: At global scope:
a.cc:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   79 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:104:11: error: request for member 'push' in 'p', which is of non-class type 'int'
  104 |         p.push(temp);
      |           ^~~~