Submission #1115017

# Submission time Handle Problem Language Result Execution time Memory
1115017 2024-11-19T22:22:57 Z RED1 medians (balkan11_medians) C++14
15 / 100
129 ms 14496 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, 0LL);
    }

    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 Correct 1 ms 2384 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Incorrect 1 ms 2384 KB Output isn't correct
4 Incorrect 1 ms 2384 KB Output isn't correct
5 Incorrect 1 ms 2552 KB Output isn't correct
6 Correct 2 ms 2384 KB Output is correct
7 Incorrect 1 ms 2384 KB Output isn't correct
8 Incorrect 1 ms 2384 KB Output isn't correct
9 Incorrect 1 ms 2384 KB Output isn't correct
10 Incorrect 1 ms 2384 KB Output isn't correct
11 Incorrect 2 ms 2384 KB Output isn't correct
12 Incorrect 2 ms 2384 KB Output isn't correct
13 Incorrect 2 ms 2384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2640 KB Output isn't correct
2 Incorrect 4 ms 2896 KB Output isn't correct
3 Incorrect 8 ms 3408 KB Output isn't correct
4 Incorrect 16 ms 4432 KB Output isn't correct
5 Incorrect 35 ms 6296 KB Output isn't correct
6 Incorrect 72 ms 10176 KB Output isn't correct
7 Incorrect 129 ms 14496 KB Output isn't correct