# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336037 | Dymo | medians (balkan11_medians) | C++14 | 34 ms | 4964 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>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define ld long double
#define ull long long
#define endl "\n"
const ll maxn=7e5+10;
const ll mod =978123409 ;
const long double pi=3.14159265359;
ll a[maxn];
bool dd[maxn];
vector<ll> ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n;
cin>>n ;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
dd[a[1]]=1;
ans.pb(a[1]);
ll st=1;
ll ed=2*n-1;
for (int i=2;i<=n;i++)
{
while (dd[st]&&st<=2*n-1) st++;
while (dd[ed]&&ed>=1) ed--;
if (a[i]==a[i-1])
{
dd[st]=1;
dd[ed]=1;
ans.pb(ed);
ans.pb(st);
ed--;
st++;
}
else if (a[i]>a[i-1])
{
if (dd[a[i]])
{
dd[ed]=1;
ans.pb(ed);
ed--;
while (dd[ed]&&ed>=1) ed--;
ans.pb(ed);
dd[ed]=1;
ed--;
}
else
{
ans.pb(a[i]);
dd[a[i]]=1;
ans.pb(ed);
dd[ed]=1;
ed--;
}
}
else
{
if (dd[a[i]])
{
ans.pb(st);
dd[st]=1;
st++;
while (dd[st]&&st<=2*n-1) st++;
ans.pb(st);
dd[st]=1;
st++;
}
else
{
ans.pb(a[i]);
dd[a[i]]=1;
ans.pb(st);
dd[st]=1;
st++;
}
}
}
for (auto to:ans) cout <<to<<" ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |