# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
54163 | zadrga | medians (balkan11_medians) | C++14 | 46 ms | 4880 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.
// 16.30
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
bool used[maxn];
int med[maxn], max_ind, min_ind, n;
vector<int> ans;
int find_max(){
while(max_ind >= 1 && used[max_ind] == 1)
max_ind--;
used[max_ind] = 1;
return max_ind;
}
int find_min(){
while(min_ind <= 2 * n - 1 && used[min_ind] == 1)
min_ind++;
used[min_ind] = 1;
return min_ind;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", med + i);
ans.pb(med[1]);
used[med[1]] = 1;
min_ind = 1;
max_ind = 2 * n - 1;
for(int i = 2; i <= n; i++){
if(med[i] == med[i - 1]){
ans.pb(find_max());
ans.pb(find_min());
}
if(med[i] > med[i - 1]){
ans.pb(find_max());
if(used[med[i]])
ans.pb(find_max());
else{
ans.pb(med[i]);
used[med[i]] = 1;
}
}
if(med[i] < med[i - 1]){
ans.pb(find_min());
if(used[med[i]])
ans.pb(find_min());
else{
ans.pb(med[i]);
used[med[i]] = 1;
}
}
}
for(int i : ans)
printf("%d ", i);
printf("\n");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |