Language: C++

#include <bits/stdc++.h>

using namespace std;

const int inf = 1e9;
const int maxn = 2e5;
tuple<int, int> mn[2][4 * maxn];

void upd(int p, int c, int v = 1, int l = 0, int r = maxn)
{
    if(r - l == 1)
    {
        mn[p % 2][v] = tuple<int, int>(c, p);
        return;
    }
    int m = (l + r) / 2;
    if(p < m)
        upd(p, c, 2 * v, l, m);
    else
        upd(p, c, 2 * v + 1, m, r);
    mn[p % 2][v] = min(mn[p % 2][2 * v], mn[p % 2][2 * v + 1]);
}

tuple<int, int> get(int a, int b, int c, int v = 1, int l = 0, int r = maxn)
{
    if(a <= l && r <= b)
        return mn[c][v];
    if(r <= a || b <= l)
        return tuple<int, int>(inf, inf);
    int m = (l + r) / 2;
    return min(get(a, b, c, 2 * v, l, m), get(a, b, c, 2 * v + 1, m ,r));
}

set<tuple<int, int, int, int, int>> que;
void query(int a, int b)
{
    if(b - a == 0)
        return;
    auto A = get(a, b, a % 2);
    auto B = get(get<1>(A), b, (a + 1) % 2);
    que.insert(tuple<int, int>(get<0>(A), get<1>(A), get<1>(B), a, b));
}

signed main()
{
    fill(mn[0], mn[0] + 4 * maxn, make_tuple(inf, inf));
    fill(mn[1], mn[1] + 4 * maxn, make_tuple(inf, inf));
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        upd(i, a[i]);
    }
    query(0, n);
    vector<int> ans;
    while(!que.empty())
    {
        int x = get<1>(*begin(que));
        int y = get<2>(*begin(que));
        int l = get<3>(*begin(que));
        int r = get<4>(*begin(que));
        que.erase(begin(que));
        ans.push_back(a[x]);
        ans.push_back(a[y]);
        query(l, x);
        query(x + 1, y);
        query(y + 1, r);
    }
    for(auto it: ans)
        cout << it << ' ';
}
//1001


Compiler output:
a.cc: In function 'void query(int, int)':
a.cc:41:69: error: no matching function for call to 'std::tuple<int, int>::tuple(std::__tuple_element_t<0, std::tuple<int, int> >&, std::__tuple_element_t<1, std::tuple<int, int> >&, std::__tuple_element_t<1, std::tuple<int, int> >&, int&, int&)'
   41 |     que.insert(tuple<int, int>(get<0>(A), get<1>(A), get<1>(B), a, b));
      |                                                                     ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 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/tuple:2323:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, std::pair<_U1, _U2>&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2323 |         tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2323:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2314:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, std::pair<_U1, _U2>&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2314 |         tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2314:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2306:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_explicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const std::pair<_U1, _U2>&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_explicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2306 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2306:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2297:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_implicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const std::pair<_U1, _U2>&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_implicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2297 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2297:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2290:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_U1, _U2>&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2290 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2290:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2282:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_U1, _U2>&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2282 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2282:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2273:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_explicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_U1, _U2>&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_explicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2273 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2273:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2263:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_implicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_U1, _U2>&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_implicitly_constructible<const _U1&, const _U2&>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2263 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2263:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2257:9: note: candidate: 'template<class _Alloc> std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_T1, _T2>&&) [with _T1 = int; _T2 = int]'
 2257 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2257:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2252:9: note: candidate: 'template<class _Alloc> std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_T1, _T2>&) [with _T1 = int; _T2 = int]'
 2252 |         tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:2252:9: note:   candidate expects 3 arguments, 5 provided
/usr/include/c++/14/tuple:2244:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, _U1&&, _U2&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_explicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2244 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2244:9: note:   candidate expects 4 arguments, 5 provided
/usr/include/c++/14/tuple:2235:9: note: candidate: 'template<class _Alloc, class _U1, class _U2, typename std::enable_if<__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, _U1&&, _U2&&) [with _U1 = _Alloc; _U2 = _U1; typename std::enable_if<std::_TupleConstraints<true, _T1, _T2>::__is_implicitly_constructible<_U1, _U2>(), bool>::type <anonymous> = _U2; _T1 = int; _T2 = int]'
 2235 |         tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
      |         ^~~~~
/usr/include/c++/14/tuple:2235:9: note:   candidate expects 4 arguments, 5 provided
/usr/include/c++/14/tuple:2228:9: note: candidate: 'template<class _Alloc, bool _Dummy, typename std::enable_if<std::_TupleConstraints<_Dummy, int, int>::__is_explicitly_constructible<const int&, const int&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const _T1&, const _T2&) [with bool _Dummy = _Alloc; typename std::enable_if<std::_TupleConstraints<_Dummy, _T1, _T2>::__is_explicitly_constructible<const _T1&, const _T2&>(), bool>::type <anonymous> = _Dummy; _T1 = int; _T2 = int]'
 2228 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2228:9: note:   candidate expects 4 arguments, 5 provided
/usr/include/c++/14/tuple:2220:9: note: candidate: 'template<class _Alloc, bool _Dummy, typename std::enable_if<std::_TupleConstraints<_Dummy, int, int>::__is_implicitly_constructible<const int&, const int&>(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&, const _T1&, const _T2&) [with bool _Dummy = _Alloc; typename std::enable_if<std::_TupleConstraints<_Dummy, _T1, _T2>::__is_implicitly_constructible<const _T1&, const _T2&>(), bool>::type <anonymous> = _Dummy; _T1 = int; _T2 = int]'
 2220 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:2220:9: note:   candidate expects 4 arguments, 5 provided
/usr/include/c++/14/tuple:2214:9: note: candidate: 'template<class _Alloc, typename std::enable_if<std::_TupleConstraints<std::is_object<_Tp>::value, int, int>::__is_explicitly_default_constructible(), bool>::type <anonymous> > std::tuple<_T1, _T2>::tuple(std::allocator_arg_t, const _Alloc&) [with typename std::enable_if<std::_TupleConstraints<std::is_object<_Alloc>::value, _T1, _T2>::__is_explicitly_default_constructible(), bool>::type <anonymous> = _Alloc; _T1 = int; _T2 = int]'
 2214 |         tuple(allocator_arg_t __tag, const _Alloc& __a)
      |         ^~~~~
/usr/include/c++/14/tuple:2214:9: note:   candidate expects 2 arguments, 5 provided
/usr/include/c++/14/tuple:2207:9: note: candidat