Submission #1115021

#TimeUsernameProblemLanguageResultExecution timeMemory
1115021RED1medians (balkan11_medians)C++17
15 / 100
109 ms14272 KiB
#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+1); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...