Submission #854337

#TimeUsernameProblemLanguageResultExecution timeMemory
854337JoksimKaktusmedians (balkan11_medians)C++17
85 / 100
19 ms1948 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n;
    cin >> n;
    bool arr[n*2];
    for(int i = 0;i < n*2;i++){
        arr[i] = false;
    }
    int xx;
    cin >> xx;
    cout << xx << " ";
    arr[xx] = true;
    int l = 1;
    if(xx == 1) l++;
    int r = 2*n-1;
    if(xx == r) r--;
    int last = xx;
    for(int i = 1;i < n;i++){
        int x;
        cin >> x;
        if(x == last){
            cout << l << " " << r << " ";
            arr[l] = true;
            while(arr[l]){
                l++;
            }
            arr[r] = true;
            while(arr[r]){
                r--;
            }
        }else if(x > last && !arr[x]){
            cout << x << " " << r << " ";
            arr[x] = true;
            arr[r] = true;
            while(arr[r]){
                r--;
            }
        }else if(x > last) {
            cout << r << " ";
            arr[r] = true;
            while(arr[r]){
                r--;
            }
            cout << r << " ";
            arr[r] = true;
            while(arr[r]){
                r--;
            }
        }else if(x < last && !arr[x]){
            cout << x << " " << l << " ";
            arr[x] = true;
            arr[l] = true;
            while(arr[l]){
                l++;
            }
        }else{
            cout << l << " ";
            arr[l] = true;
            while(arr[l]){
                l++;
            }
            cout << l << " ";
            arr[l] = true;
            while(arr[l]){
                l++;
            }
        }
        last = x;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...