# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330767 | BeanZ | medians (balkan11_medians) | C++14 | 32 ms | 3564 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.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 2e5 + 5;
const int lg = 60;
const int mod = 998244353;
const long long oo = 1e18;
const int lim = 1e6 + 5;
long double eps = 1e-3;
ll vis[N], b[N], a[N];
ll l, r;
void addl(ll id){
while (vis[l]) l++;
b[id] = l;
vis[l] = 1;
}
void addr(ll id){
while (vis[r]) r--;
b[id] = r;
vis[r] = 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("test.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];
b[1] = a[1];
vis[b[1]] = 1;
l = 1, r = 2 * n - 1;
for (int i = 2; i <= n; i++){
if (a[i] == a[i - 1]){
addl(i * 2 - 2);
addr(i * 2 - 1);
} else if (a[i] > a[i - 1]){
if (vis[a[i]]){
addr(i * 2 - 2);
addr(i * 2 - 1);
} else {
vis[a[i]] = 1;
b[i * 2 - 2] = a[i];
addr(i * 2 - 1);
}
} else {
if (vis[a[i]]){
addl(i * 2 - 2);
addl(i * 2 - 1);
} else {
vis[a[i]] = 1;
b[i * 2 - 2] = a[i];
addl(i * 2 - 1);
}
}
}
for (int i = 1; i <= (2 * n - 1); i++) cout << b[i] << " ";
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |