# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
368554 | cpp219 | medians (balkan11_medians) | C++14 | 125 ms | 12268 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e16 + 7;
typedef pair<int,int> LL;
vector<ll> ans;
set<ll> s;
ll n,b[N],was[N];
void Out(){
for (auto i : s) cout<<i<<" ";
}
void DE(){
ans.push_back(*prev(s.end())); s.erase(prev(s.end()));
ans.push_back(*prev(s.end())); s.erase(prev(s.end()));
}
void DS(){
ans.push_back(*s.begin()),s.erase(s.begin());
ans.push_back(*s.begin()),s.erase(s.begin());
}
int main(){
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n;
for (ll i = 1;i <= 2*n - 1;i++) s.insert(i);
for (ll i = 1;i <= n;i++) cin>>b[i],s.erase(b[i]);
ans.push_back(b[1]); was[b[1]] = 1;
for (ll i = 2;i <= n;i++){
if (!was[b[i]]) ans.push_back(b[i]); //Out(); cout<<" x ";
if (was[b[i]]){
if (b[i - 1] > b[i]) DS();
if (b[i - 1] < b[i]) DE();
if (b[i - 1] == b[i]){
ans.push_back(*s.begin()),s.erase(s.begin());
ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
}
}
else if (b[i - 1] > b[i]) ans.push_back(*s.begin()),s.erase(s.begin());
else if (b[i - 1] < b[i]) ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
was[b[i]] = 1; //Out(); cout<<"\n";
}
//exit(0);
//for (auto i : s) cout<<i<<" "; exit(0);
for (auto i : ans) cout<<i<<" ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |