Submission #1866909


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define MAXI 200020
#define u(x, a, b) for(ll x = a; x < b; x++)
#define d(x, a, b) for(ll x = a; x > b; x--)

pair<ll, ll> st0[MAXI][20];// 0 mod 2
pair<ll, ll> st1[MAXI][20];// 1 mod 2

vector<ll> in;
deque< pair<ll, ll> > ans;

pair<ll, ll> queryst0(ll le, ll ri){
    //cerr<<"L R 1 : "<<le<<' '<<ri<<'\n';
    int k = log2(ri-le);
    ll ans = min(st0[le][k].first, st0[ri-(1 << k)][k].first); // <-- for query [l, r]
    ll pos;
    if(ans == st0[le][k].first){
        pos = st0[le][k].second;
    }
    else{
        //cerr<<"D : "<<ri-(1<<k)<<'\n';
        pos = st0[ri-(1 << k)][k].second;
    }
    pair<ll, ll> t = make_pair(ans, pos);
    return t;
}

pair<ll, ll> queryst1(ll le, ll ri){
    //cerr<<"L R 1 : "<<le<<' '<<ri<<'\n';
    int k = log2(ri-le);
    //cerr<<"D : "<<ri-(1<<k)<<'\n';
    ll ans = min(st1[le][k].first, st1[ri-(1 << k)][k].first); // <-- for query [l, r]
    ll pos;
    if(ans == st1[le][k].first){
        pos = st1[le][k].second;
    }
    else{

        pos = st1[ri-(1 << k)][k].second;
    }
    pair<ll, ll> t = make_pair(ans, pos);
    return t;
}

pair<ll, ll> greedy(ll le, ll ri){
    ll min1, tar1, min2, tar2;

    if(le >= ri){
        return make_pair(MAXI, MAXI);
    }

    if(le%2){
        pair<ll, ll> v = queryst1(le, ri);
        tar1 = v.second;
        min1 = v.first;
    }
    else{
        pair<ll, ll> v = queryst0(le, ri);
        tar1 = v.second;
        min1 = v.first;
    }

    if((tar1+1)%2){
        pair<ll, ll> v = queryst1(tar1+1, ri);
        tar2 = v.second;
        min2 = v.first;
    }
    else{
        pair<ll, ll> v = queryst0(tar1+1, ri);
        tar2 = v.second;
        min2 = v.first;
    }
    pair<ll, ll> a[3];
    a[0] = greedy(le, tar1);
    a[1] = greedy(tar1+1, tar2);
    a[2] = greedy(tar2+1, ri);
    sort(a, a+3);
    d(one, 2, -1){
        if(a[one].first < MAXI){
            ans.push_front(a[one]);
        }
    }
    return make_pair(min1, min2);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, temp;
    cin >> n;
    u(three, 0, n){
        cin >> temp;
        in.push_back(temp);
    }
    //sparse table
    int pwr = log2(n);
    for(int j = 0;j <= pwr;j++){
        for(int i = 0; i < n;i ++){
            if(i + (1 << j) - 1 < n){
                pair<ll, ll> imax = make_pair(MAXI, i);
                pair<ll, ll> curi = make_pair(in[i], i), cur0, cur1;
                if(j){
                    ll minst0 = min(st0[i][j-1].first, st0[i + (1 << (j-1))][j-1].first), posmin0;
                    ll minst1 = min(st1[i][j-1].first, st1[i + (1 << (j-1))][j-1].first), posmin1;
                    if(minst0 == st0[i][j-1].first){
                        posmin0 = st0[i][j-1].second;
                    }
                    else{
                        posmin0 = st0[i + (1 << (j-1))][j-1].second;
                    }
                    if(minst1 == st1[i][j-1].first){
                        posmin1 = st1[i][j-1].second;
                    }
                    else{
                        posmin1 = st1[i + (1 << (j-1))][j-1].second;
                    }
                    cur0 = make_pair(minst0, posmin0);
                    cur1 = make_pair(minst1, posmin1);
                }
                st0[i][j] = (j ? cur0 : (i%2==1 ? imax : curi));//if j = 0, i%2 = 0 then st0[i][0] = arr[i]
                st1[i][j] = (j ? cur1 : (i%2==1 ? curi : imax));//opposite for st1
            }
            else{
                st0[i][j] = make_pair(MAXI, MAXI);
                st1[i][j] = make_pair(MAXI, MAXI);
            }
        }
    }
    pair<ll, ll> temp2 = greedy(0, n);
    ans.push_front(temp2);
    u(three, 0, n/2){
        cout << ans[three].first << ' ' << ans[three].second << ' ';
    }
}

Submission Info

Submission Time
Task E - Young Maids
User vjudge3
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3860 Byte
Status WA
Exec Time 204 ms
Memory 143856 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 8
WA × 15
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt
Case Name Status Exec Time Memory
0_00.txt AC 4 ms 2560 KB
0_01.txt AC 1 ms 2304 KB
0_02.txt AC 1 ms 2304 KB
1_00.txt AC 1 ms 2304 KB
1_01.txt AC 1 ms 2304 KB
1_02.txt AC 203 ms 143856 KB
1_03.txt AC 199 ms 143856 KB
1_04.txt AC 204 ms 143728 KB
1_05.txt WA 201 ms 129776 KB
1_06.txt WA 202 ms 129776 KB
1_07.txt WA 200 ms 129776 KB
1_08.txt WA 199 ms 129776 KB
1_09.txt WA 200 ms 143728 KB
1_10.txt WA 199 ms 140144 KB
1_11.txt WA 200 ms 139504 KB
1_12.txt WA 194 ms 127472 KB
1_13.txt WA 204 ms 129648 KB
1_14.txt WA 199 ms 129648 KB
1_15.txt WA 200 ms 129648 KB
1_16.txt WA 203 ms 129648 KB
1_17.txt WA 203 ms 129648 KB
1_18.txt WA 200 ms 129648 KB
1_19.txt WA 199 ms 129648 KB