Submission #51631

# Submission time Handle Problem Language Result Execution time Memory
51631 2018-06-19T10:36:35 Z someone_aa medians (balkan11_medians) C++17
10 / 100
77 ms 6288 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100100;
int tree[8*maxn], b[maxn], a[2*maxn], n;
bool used[2*maxn];

void update(int x, int li=0, int ri=2*n,int index=1) {
    if(li==ri) tree[index] = 1;
    else {
        int mid = (li+ri) /2;
        if(x <= mid) update(x, li, mid, 2*index);
        else if(x > mid) update(x, mid+1, ri, 2*index+1);
    }
}

int query(int ql, int qr, int li=0, int ri=2*n, int index=1) {
    if(qr < ql) return 0;
    if(li > qr || ri < ql) return 0;
    else if(li >= ql && ri <= qr) return tree[index];
    else {
        int mid = (li+ri)/2;
        return query(ql,qr,li,mid,2*index) + query(ql,qr,mid+1,ri,2*index+1);
    }
}

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>b[i];
    }

    a[1] = b[1];
    used[b[1]] = true;

    update(b[1]);

    int st = 1, fh = 2*n-1;

    if(b[1] == 1) st = 2;
    else st = 1;

    if(b[1] == 2*n-1) fh = 2*n-2;
    else fh = 2*n-1;

    for(int i=2;i<=n;i++) {
        //cout<<i<<" -> ";
        if(used[b[i]]) {
            //cout<<"Placing A: "<<st<<" "<<fh<<" -> ";
            a[2*(i-1)] = st;
            a[2*(i-1)+1] = fh;
            update(st); update(fh);
            used[st] = used[fh] = true;
            while(used[st] && st < 2 * n) st++;
            while(used[fh] && fh > 0) fh--;
            //cout<<st<<" "<<fh<<"\n";
        }
        else {
            //cout<<"Placing B: "<<st<<" "<<fh<<" -> ";
            a[2*(i-1)] = b[i];
            used[b[i]] = true;
            update(b[i]);
            int temp = query(1, b[i]-1);

            while(used[st] && st < 2 * n) st++;
            while(used[fh] && fh > 0) fh--;

            if(temp == (i-1)) {
                // stavi pogolemo
                a[2*(i-1)+1] = fh;
                used[fh] = true;
                update(fh);
                while(used[fh] && fh > 0) fh--;
            }
            else if(temp < (i-1)) {
                // stavi pomalo
                a[2*(i-1)+1] = st;
                used[st] = true;
                update(st);
                while(used[st] && st < 2 * n) st++;
            }
            //cout<<st<<" "<<fh<<"\n";
        }
    }

    for(int i=1;i<=2*n-1;i++) {
        cout<<a[i]<<" ";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 2 ms 452 KB Output isn't correct
3 Incorrect 2 ms 452 KB Output isn't correct
4 Incorrect 3 ms 520 KB Output isn't correct
5 Incorrect 3 ms 520 KB Output isn't correct
6 Correct 2 ms 636 KB Output is correct
7 Incorrect 2 ms 640 KB Output isn't correct
8 Incorrect 2 ms 644 KB Output isn't correct
9 Incorrect 4 ms 692 KB Output isn't correct
10 Incorrect 2 ms 696 KB Output isn't correct
11 Incorrect 2 ms 696 KB Output isn't correct
12 Incorrect 3 ms 788 KB Output isn't correct
13 Incorrect 3 ms 836 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 836 KB Output isn't correct
2 Incorrect 6 ms 904 KB Output isn't correct
3 Incorrect 9 ms 1176 KB Output isn't correct
4 Incorrect 15 ms 1488 KB Output isn't correct
5 Incorrect 27 ms 2224 KB Output isn't correct
6 Incorrect 50 ms 3844 KB Output isn't correct
7 Incorrect 77 ms 6288 KB Output isn't correct