Submission #1115020

# Submission time Handle Problem Language Result Execution time Memory
1115020 2024-11-19T22:32:40 Z RED1 medians (balkan11_medians) C++14
0 / 100
116 ms 26316 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Algerian ios::sync_with_stdio(false);
#define OI cin.tie(nullptr);
const int MAX = 200001;


struct segtree {
    int size;
    vector<int> sums;

    void init(int n){
        size = 1;
        while(size<n) size *= 2;
        sums.assign(2*size, 0);
    }

    void set(int i, int v, int x, int lx, int rx){
        if(rx-lx==1){
            sums[x]=v;
            return;
        }
        int m = (lx+rx)/2;
        if(i<m) set(i,v,2*x+1,lx,m);
        else set(i,v,2*x+2,m,rx);

        sums[x]=sums[2*x+1]+sums[2*x+2];
    }

    void set(int i, int v){
        set(i,v,0,0,size);
    }

    ll sum(int l, int r, int x, int lx, int rx){
        if(lx>=r ||l>=rx) return 0;
        if(lx>=l && rx<=r) return sums[x];
        int m = (lx+rx)/2;
        ll s1 = sum(l,r,2*x+1,lx,m);
        ll s2 = sum(l,r,2*x+2,m,rx);
        return s1+s2;
    }

    ll sum(int l, int r){
        return sum(l,r,0,0,size);
    }
};


int main()
{
    Algerian OI;
    int N; cin >> N;
    vector<int> B(N);
    for(auto &i : B) cin >> i;
    segtree ST;
    ST.init(MAX);
    map<int,bool> put;
    vector<int> ans;
    set<int> nums;
    for(int i=1;i<=2*N-1;++i) nums.insert(i);

    ans.push_back(B[0]);
    put[B[0]]=true;
    ST.set(B[0],1);
    nums.erase(nums.find(B[0]));
    int j = 2;
    for(int i = 1;i<N;++i) {
        int cur = B[i];
        if(!put[cur]) {
            put[cur]=true;
            ++j;
            nums.erase(nums.find(cur));
            ans.push_back(cur);
            ST.set(cur,1);
        }
        int numofbigger = ST.sum(cur+1,MAX);
        while(j<=2*(i+1)-1) {
            if(numofbigger<=i) {
                auto it = nums.lower_bound(cur);
                put[*it]=true;
                ans.push_back(*it);
                ST.set(*it,1);
                ++numofbigger;
                nums.erase(it);
            }
            else {
                auto it = nums.begin();
                put[*it]=true;
                ans.push_back(*it);
                ST.set(*it,1);
                nums.erase(it);
            }
            ++j;
        }
    }
    for(auto i: ans) cout << i << ' ';
}
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 4688 KB Execution killed with signal 6
2 Runtime error 4 ms 4688 KB Execution killed with signal 6
3 Runtime error 4 ms 4688 KB Execution killed with signal 6
4 Runtime error 5 ms 4688 KB Execution killed with signal 6
5 Runtime error 4 ms 4700 KB Execution killed with signal 6
6 Runtime error 4 ms 4700 KB Execution killed with signal 6
7 Runtime error 5 ms 4600 KB Execution killed with signal 6
8 Runtime error 4 ms 4700 KB Execution killed with signal 6
9 Runtime error 5 ms 4704 KB Execution killed with signal 6
10 Runtime error 5 ms 4700 KB Execution killed with signal 6
11 Runtime error 6 ms 4700 KB Execution killed with signal 6
12 Runtime error 5 ms 4856 KB Execution killed with signal 6
13 Runtime error 5 ms 4956 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5212 KB Execution killed with signal 6
2 Runtime error 8 ms 5724 KB Execution killed with signal 6
3 Runtime error 12 ms 6488 KB Execution killed with signal 6
4 Runtime error 20 ms 8284 KB Execution killed with signal 6
5 Runtime error 37 ms 11728 KB Execution killed with signal 6
6 Runtime error 73 ms 18724 KB Execution killed with signal 6
7 Runtime error 116 ms 26316 KB Execution killed with signal 6