Language: C++

#include <bits/stdc++.h>
#define maxn 300100
using namespace std;
typedef pair par;
struct data{int l,r,w,x,y;int operator<(const data& d)const{return w>d.w;}};
priority_queuepq;
int n,a[2][maxn>>1];
par s[2][19][maxn>>1];
par qry(int d,int l,int r){
    int len=1,k=0;
    l=(l+1)>>1,r=(r+1)>>1;
    while((len<<1)     return min(s[d][k][l],s[d][k][r-(1< }
data get(int l,int r){
    par a1=qry(l&1,l,r-1);
    par b1=qry(~l&1,a1.second+1,r);
    data d;
    d.l=l,d.r=r,d.w=a1.first;
    d.x=a1.second,d.y=b1.second;
    return d;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i&1][(i+1)>>1]);
    memset(s,0x3f,sizeof(s));
    for(int d=0;d<2;++d){
        for(int i=1;i<=((n+1)>>1);++i)s[d][0][i]=par(a[d][i],(i<<1)-d);
        for(int i=1;i<19;++i)
            for(int j=1;j<=((n+1)>>1);++j)
                s[d][i][j]=min(s[d][i-1][j],s[d][i-1][j+(1<     }
    pq.push(get(1,n));
    while(pq.size()){
        data ret=pq.top();pq.pop();
//        printf("[%d,%d(%d,%d)]",ret.l,ret.r,ret.x,ret.y);
        printf("%d %d ",a[ret.x&1][(ret.x+1)>>1],a[ret.y&1][(ret.y+1)>>1]);
        if(ret.l<=ret.x-1)pq.push(get(ret.l,ret.x-1));
        if(ret.x+1<=ret.y-1)pq.push(get(ret.x+1,ret.y-1));
        if(ret.r>=ret.y+1)pq.push(get(ret.y+1,ret.r));
    }
}

Compiler output:
a.cc:4:9: error: typedef declared 'auto'
    4 | typedef pair par;
      |         ^~~~
a.cc:6:1: error: 'priority_queuepq' does not name a type
    6 | priority_queuepq;
      | ^~~~~~~~~~~~~~~~
a.cc:13:1: error: reference to 'data' is ambiguous
   13 | data get(int l,int r){
      | ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:5:8: note:                 'struct data'
    5 | struct data{int l,r,w,x,y;int operator<(const data& d)const{return w>d.w;}};
      |        ^~~~
a.cc: In function 'int main()':
a.cc:25:12: error: 's' was not declared in this scope
   25 |     memset(s,0x3f,sizeof(s));
      |            ^
a.cc:30:65: error: expected primary-expression before '}' token
   30 |                 s[d][i][j]=min(s[d][i-1][j],s[d][i-1][j+(1<     }
      |                                                                 ^
a.cc:30:60: error: expected ')' before '}' token
   30 |                 s[d][i][j]=min(s[d][i-1][j],s[d][i-1][j+(1<     }
      |                                                         ~  ^    ~
      |                                                            )
a.cc:30:60: error: expected ']' before '}' token
   30 |                 s[d][i][j]=min(s[d][i-1][j],s[d][i-1][j+(1<     }
      |                                                            ^    ~
      |                                                            ]
a.cc:31:5: error: 'pq' was not declared in this scope
   31 |     pq.push(get(1,n));
      |     ^~
a.cc:31:16: error: no matching function for call to 'get(int, int&)'
   31 |     pq.push(get(1,n));
      |             ~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1250:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(pair<_Tp1, _Tp2>&)'
 1250 |     get(pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1250:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1255:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(pair<_Tp1, _Tp2>&&)'
 1255 |     get(pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1255:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1260:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const pair<_Tp1, _Tp2>&)'
 1260 |     get(const pair<_Tp1, _Tp2>& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1260:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1265:5: note: candidate: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(const pair<_Tp1, _Tp2>&&)'
 1265 |     get(const pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1265:5: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2445:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(tuple<_Elements ...>&)'
 2445 |     get(tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2445:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/tuple:2451:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const tuple<_Elements ...>&)'
 2451 |     get(const tuple<_Elements...>& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2451:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/tuple:2457:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(tuple<_Elements ...>&&)'
 2457 |     get(tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2457:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/tuple:2466:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&)'
 2466 |     get(const tuple<_Elements...>&& __t) noexcept
      |     ^~~
/usr/include/c++/14/tuple:2466:5: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/14/functional:65,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/array:390:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(array<_Tp, _Nm>&)'
  390 |     get(array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:390:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/array:399:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(array<_Tp, _Nm>&&)'
  399 |     get(array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:399:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/array:408:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const array<_Tp, _Nm>&)'
  408 |     get(const array<_Tp, _Nm>& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:408:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/array:417:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp&& std::get(const array<_Tp, _Nm>&&)'
  417 |     get(const array<_Tp, _Nm>&& __arr) noexcept
      |     ^~~
/usr/include/c++/14/array:417:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1272:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_T1, _T2>&)'
 1272 |     get(pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1272:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1277:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_T1, _T2>&)'
 1277 |     get(const pair<_Tp, _Up>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1277:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1282:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(pair<_T1, _T2>&&)'
 1282 |     get(pair<_Tp, _Up>&& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1282:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1287:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const pair<_T1, _T2>&&)'
 1287 |     get(const pair<_Tp, _Up>&& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1287:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1292:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_Up, _Tp>&)'
 1292 |     get(pair<_Up, _Tp>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1292:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1297:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_Up, _Tp>&)'
 1297 |     get(const pair<_Up, _Tp>& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1297:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1302:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(pair<_Up, _Tp>&&)'
 1302 |     get(pair<_Up, _Tp>&& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1302:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_pair.h:1307:5: note: candidate: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const pair<_Up, _Tp>&&)'
 1307 |     get(const pair<_Up, _Tp>&& __p) noexcept
      |     ^~~
/usr/include/c++/14/bits/stl_pair.h:1307:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/tuple:2476:5: note: candidate: 'template<long unsigned int __i, class ... _Elements> constexpr std::__enable_if_t<(__i >= sizeof... (_Types))> std::get(const tuple<_Elements ...>&)' (deleted)
 2476 |     get(const tuple<_Elements...>&) = delete;
      |     ^~~
/usr/include/c++/14/tuple:2476:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/t