# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1276824 | Tien_Noob | medians (balkan11_medians) | C++20 | 14 ms | 4088 KiB |
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e5;
int a[N + 1], n;
bool visited[2 * N];
int find_first()
{
static int st = 1;
while(visited[st])
{
++st;
}
visited[st] = true;
return st;
}
int find_last()
{
static int st = 2 * n - 1;
while(visited[st])
{
--st;
}
visited[st] = true;
return st;
}
void read()
{
cin >> n;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
}
void solve()
{
cout << a[1] << ' ';
visited[a[1]] = true;
for (int i = 2; i <= n; ++ i)
{
if (a[i] == a[i - 1])
{
cout << find_first() << ' ' << find_last() << ' ';
}
else if (a[i] > a[i - 1])
{
if (visited[a[i]])
{
cout << find_last() << ' ' << find_last() << ' ';
}
else
{
visited[a[i]] = true;
cout << a[i] << ' ' << find_last() << ' ';
}
}
else
{
if (visited[a[i]])
{
cout << find_first() << ' ' << find_first() << ' ';
}
else
{
visited[a[i]] = true;
cout << a[i] << ' ' << find_first() << ' ';
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |