Language: C++

#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n , a[N] , index[N];
int T[4 * N][3] , d[4 * N];

void build(int v,int s,int e){
    if(s == e){
        if(s % 2){
            T[v][0] = a[s];
            T[v][1] = inf;
        }
        else{
            T[v][0] = inf;
            T[v][1] = a[s];
        }
        return ;
    }
    int m = (s + e) / 2;
    build(2*v , s , m);
    build(2*v+1 , m+1 , e);
    T[v][0] = min(T[2*v][0] , T[2*v+1][0]);
    T[v][1] = min(T[2*v][1] , T[2*v+1][1]);
}

void push(int v,int s,int e){
    if(d[v] == 0)return ;
    swap(T[v][0] , T[v][1]);
    if(s != e){
        d[2*v] ^= d[v];
        d[2*v+1] ^= d[v];
    }
    d[v] = 0;
}

void update(int v,int s,int e,int l,int r){
    push(v , s , e);
    if(l > r)return ;
    if(s == l && e == r){
        d[v] ^= 1;
        push(v , s , e);
        return ;
    }
    int m = (s + e) / 2;
    update(2*v , s , m , l , min(r , m));
    update(2*v+1 , m+1 , e , max(m+1,l) , r);
    T[v][0] = min(T[2*v][0] , T[2*v+1][0]);
    T[v][1] = min(T[2*v][1] , T[2*v+1][1]);
}

void update1(int v,int s,int e,int pos){
    push(v , s , e);
    if(s == e){
        T[v][0] = T[v][1] = inf;
        return ;
    }
    int m = (s + e) / 2;
    if(pos <= m){
        update1(2*v , s , m , pos);
        push(2*v+1 , m+1 , e);
    }
    else{
        update1(2*v+1 , m+1 , e , pos);
        push(2*v , s , m);
    }
    T[v][0] = min(T[2*v][0] , T[2*v+1][0]);
    T[v][1] = min(T[2*v][1] , T[2*v+1][1]);
}

int get(int v,int s,int e,int l,int r,int ind){
    push(v , s , e);
    if(l > r)return inf;
    if(s == l && e == r)return T[v][ind];
    int m = (s + e) / 2;
    return min( get(2*v , s , m , l , min(r , m) , ind) , get(2*v+1 , m+1 , e , max(m+1,l) , r , ind) );
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        index[a[i]] = i;
    }
    build(1 , 1 , n);
    int l = n;
    for(int i=1;i<=n/2;i++){
        int A = get(1 , 1 , n , 1 , n , 0);
        int B = get(1 , 1 , n , index[A] + 1 , min(n , index[A] + l - 1) , 1);
        printf("%d %d ",A,B);
        update(1 , 1 , n , index[A] + 1 , index[B] - 1);
        update1(1 , 1 , n , index[A]);
        update1(1 , 1 , n , index[B]);
        l -= 2;
    }
    cout<<endl;
    return 0;
}



Compiler output:
a.cc:21:23: error: 'int index [200005]' redeclared as different kind of entity
   21 | int n , a[N] , index[N];
      |                       ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:6:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:99:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   99 |         index[a[i]] = i;
      |              ^
a.cc:105:38: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  105 |         int B = get(1 , 1 , n , index[A] + 1 , min(n , index[A] + l - 1) , 1);
      |                                      ^
a.cc:105:61: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  105 |         int B = get(1 , 1 , n , index[A] + 1 , min(n , index[A] + l - 1) , 1);
      |                                                             ^
a.cc:107:33: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  107 |         update(1 , 1 , n , index[A] + 1 , index[B] - 1);
      |                                 ^
a.cc:107:48: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  107 |         update(1 , 1 , n , index[A] + 1 , index[B] - 1);
      |                                                ^
a.cc:108:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  108 |         update1(1 , 1 , n , index[A]);
      |                                  ^
a.cc:109:34: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  109 |         update1(1 , 1 , n , index[B]);
      |                                  ^