Submission #1003011

#TimeUsernameProblemLanguageResultExecution timeMemory
1003011AdamGSmedians (balkan11_medians)C++17
0 / 100
1095 ms21212 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
int T[LIM], odw[LIM], czy[LIM];
set<int>S;
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  rep(i, 2*n-1) S.insert(i+1);
  rep(i, n) {
    cin >> T[i];
    if(!odw[T[i]]) {
      czy[T[i]]=1;
      odw[T[i]]=1;
      S.erase(T[i]);
    }
  }
  vector<int>ans;
  for(int i=n-1; i>0; --i) {
    if(T[i]==T[i-1]) {
      auto it=S.lower_bound(T[i]);
      auto a=*it;
      ans.pb(a);
      --it;
      auto b=*it;
      ans.pb(b);
      S.erase(a);
      S.erase(b);
    } else if(T[i]<T[i-1]) {
      auto it=S.lower_bound(T[i]);
      --it;
      auto a=*it;
      if(czy[i]) a=T[i];
      else --it;
      auto b=*it;
      ans.pb(a);
      ans.pb(b);
      if(!czy[i]) S.erase(a);
      S.erase(b);
    } else { 
      auto it=S.lower_bound(T[i]);
      auto a=*it;
      if(czy[i]) a=T[i];
      else ++it;
      auto b=*it;
      ans.pb(a);
      ans.pb(b);
      if(a!=b) S.erase(a);
      S.erase(b);
    }
  }
  ans.pb(T[0]);
  reverse(all(ans));
  for(auto i : ans) cout << i << " ";
  cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...