Submission #51635

# Submission time Handle Problem Language Result Execution time Memory
51635 2018-06-19T11:30:14 Z someone_aa medians (balkan11_medians) C++17
15 / 100
300 ms 10740 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);

        tree[index] = tree[2*index] + tree[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]);

    set<int>nums;
    for(int i=1;i<=2*n-1;i++) nums.insert(i);

    nums.erase(b[1]);

    for(int i=2;i<=n;i++) {
        int st = *(nums.begin());
        int fh;
        for(int j:nums) {
            fh = j;
        }
        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;
            nums.erase(st);
            nums.erase(fh);
            //cout<<st<<" "<<fh<<"\n";
        }
        else {
            //cout<<"Placing B: "<<st<<" "<<fh<<" -> ";
            a[2*(i-1)] = b[i];
            used[b[i]] = true;
            nums.erase(b[i]);
            update(b[i]);
            int temp = query(1, b[i]-1);
            if(temp == (i-1)) {
              //  cout<<"Stavljam pogolemo\n";
                a[2*(i-1)+1] = fh;
                used[fh] = true;
                update(fh);
                nums.erase(fh);
            }
            else if(temp < (i-1)) {
                //cout<<"Stavljam pomalo\n";
                a[2*(i-1)+1] = st;
                used[st] = true;
                nums.erase(st);
                update(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 376 KB Output isn't correct
3 Correct 2 ms 436 KB Output is correct
4 Incorrect 3 ms 548 KB Integer 0 violates the range [1, 79]
5 Incorrect 2 ms 692 KB Integer 0 violates the range [1, 99]
6 Correct 2 ms 692 KB Output is correct
7 Incorrect 2 ms 748 KB Output isn't correct
8 Incorrect 2 ms 748 KB Integer 0 violates the range [1, 159]
9 Incorrect 2 ms 748 KB Integer 0 violates the range [1, 179]
10 Incorrect 2 ms 748 KB Integer 0 violates the range [1, 199]
11 Incorrect 4 ms 748 KB Integer 0 violates the range [1, 599]
12 Incorrect 6 ms 748 KB Integer 0 violates the range [1, 1199]
13 Incorrect 10 ms 764 KB Integer 0 violates the range [1, 1999]
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 908 KB Integer 0 violates the range [1, 3999]
2 Incorrect 163 ms 1164 KB Integer 0 violates the range [1, 7999]
3 Execution timed out 700 ms 1748 KB Time limit exceeded
4 Execution timed out 1084 ms 2488 KB Time limit exceeded
5 Execution timed out 1077 ms 4124 KB Time limit exceeded
6 Execution timed out 1075 ms 7580 KB Time limit exceeded
7 Execution timed out 1088 ms 10740 KB Time limit exceeded