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[800000];
 
struct section{
    int first;
    int last;
    int min;
  	
};
bool operator> (const section &s1,const section &s2){
    return s1.min>s2.min;
};
 
 
int d1[800000],d2[800000];
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;
int pos[210000];
void GO(){
    while(!p.empty()){
        section s=p.top();
        p.pop();
        int min2;
        if(pos[s.min]%2){
            min2=search2(pos[s.min]+1,s.last,0,0,n-1);
        }
        else{
            min2=search1(pos[s.min]+1,s.last,0,0,n-1);
        }
      	section 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,n-1)};
            else
            t={s.first,pos[s.min]-1,search2(s.first,pos[s.min]-1,0,0,n-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,n-1)};
            else
            t={pos[s.min]+1,pos[min2]-1,search1(pos[s.min]+1,pos[min2]-1,0,0,n-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,n-1)};
            else
            t={pos[min2]+1,s.last,search1(pos[min2]+1,s.last,0,0,n-1)};
            p.push(t);
        }
        printf("%d %d",s.min,min2)
    }
}
main(){
    cin>>n;
    int 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]);
    }
    section temp{0,n-1,d2[0]};
  	p.push(temp);
    GO();
    return 0;
}

Compiler output:
a.cc: In function 'void GO()':
a.cc:76:35: error: expected ';' before '}' token
   76 |         printf("%d %d",s.min,min2)
      |                                   ^
      |                                   ;
   77 |     }
      |     ~                              
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:85:25: error: expected ';' before 'pos'
   85 |         scanf("%d",&a+i)
      |                         ^
      |                         ;
   86 |         pos[a[i]]=i;
      |         ~~~