# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
372447 | Killer2501 | medians (balkan11_medians) | C++14 | 103 ms | 11884 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 pb push_back
#define vii vector<int>
#define task "media"
#define pll pair<ll, ll>
#define pii pair< pll, ll >
#define fi first
#define se second
using namespace std;
using ll = long long ;
using ull = unsigned long long;
const int N = 3e5+5;
const ll mod = 1e9+7;
const ll base1 = 1313;
const ll base2 = 3113;
ll m, n, k, t, T, ans, a[N], b[N], c[N], lab[N], tong, cur;
vector<ll> kq;
set<ll> st;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)cin >> b[i];
kq.pb(b[1]);
for(int i = 1; i <= n*2-1; i ++)st.insert(i);
st.erase(b[1]);
for(int i = 2; i <= n; i ++)
{
if(st.find(b[i]) != st.end())
{
kq.pb(b[i]);
st.erase(b[i]);
if(b[i] > b[i-1])
{
kq.pb(*st.rbegin());
st.erase(*st.rbegin());
}
else
{
kq.pb(*st.begin());
st.erase(*st.begin());
}
}
else
{
if(b[i] == b[i-1])
{
kq.pb(*st.begin());
st.erase(*st.begin());
kq.pb(*st.rbegin());
st.erase(*st.rbegin());
}
else if(b[i] < b[i-1])
{
kq.pb(*st.begin());
st.erase(*st.begin());
kq.pb(*st.begin());
st.erase(*st.begin());
}
else
{
kq.pb(*st.rbegin());
st.erase(*st.rbegin());
kq.pb(*st.rbegin());
st.erase(*st.rbegin());
}
}
}
for(ll x : kq)cout << x <<" ";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".in", "r"))
{
freopen(task".in","r",stdin);
freopen(task".out","w",stdout);
}
int ntest = 1;
//cin >> ntest;
for(int tt = 1; tt <= ntest; tt ++)
sol();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |