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 section{
    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(first+1=last) return a[first];
    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(first+1=last) return a[first];
    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;
  	if(n==4) return 0;
    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 'int search1(int, int, int, int, int)':
a.cc:28:17: error: lvalue required as left operand of assignment
   28 |         if(first+1=last) return a[first];
      |            ~~~~~^~
a.cc: In function 'int search2(int, int, int, int, int)':
a.cc:36:17: error: lvalue required as left operand of assignment
   36 |         if(first+1=last) return a[first];
      |            ~~~~~^~
a.cc: At global scope:
a.cc:81:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   81 | main(){
      | ^~~~