Submission #51635

#TimeUsernameProblemLanguageResultExecution timeMemory
51635someone_aamedians (balkan11_medians)C++17
15 / 100
1088 ms10740 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...