# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480731 | TranGiaHuy1508 | medians (balkan11_medians) | C++17 | 27 ms | 4804 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.
// C++ Template
#include "bits/stdc++.h"
using namespace std;
// Type
typedef long long ll;
typedef long double ld;
// Pair/Vector
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
// Macro
#define stat(x) x && cout << "YES\n" || cout << "NO\n";
#ifdef LOCAL
#define debug(x) cout << #x << " = " << x << "\n";
#else
#define debug(x) ;
#endif
// Custom output
template <class A, class B>
ostream& operator << (ostream& out, pair<A, B> x){
out << "(" << x.first << ", " << x.second << ")";
return out;
}
template <class T>
ostream& operator << (ostream& out, vector<T> x){
out << "[";
for (int i=0; i<x.size(); i++){
if (i) out << ", ";
out << x[i];
}
out << "]";
return out;
}
void fastio(string finp = "", string fout = ""){
if (fopen(finp.c_str(), "r")){
freopen(finp.c_str(), "r", stdin);
freopen(fout.c_str(), "w", stdout);
}
}
// Const
const int interactive = 0;
const ld PI = acos(-1.0);
const ll allmod[2] = {int(1e9)+7, 998244353};
const ll mod = allmod[0];
const ll maxn = 2e5;
const ll inf = 1e18;
const int multitest = 0;
#define int long long
vi v, res;
void main_program(){
int n; cin >> n;
v.assign(n*2, 0);
int crr; cin >> crr;
v[crr] = 1;
res.push_back(crr);
int l = 1, r = 2*n-1;
for (int i=0; i<n-1; i++){
int x; cin >> x;
if (x == crr){
while (v[l]) l++;
while (v[r]) r--;
res.push_back(l);
res.push_back(r);
v[l] = v[r] = 1;
}
else if (x > crr){
if (!v[x]){
v[x] = 1;
res.push_back(x);
}
else{
while (v[r]) r--;
res.push_back(r);
v[r] = 1;
}
while (v[r]) r--;
res.push_back(r);
v[r] = 1;
}
else{
if (!v[x]){
v[x] = 1;
res.push_back(x);
}
else{
while (v[l]) l++;
res.push_back(l);
v[l] = 1;
}
while (v[l]) l++;
res.push_back(l);
v[l] = 1;
}
crr = x;
}
for (int i=0; i<res.size(); i++) cout << res[i] << " ";
}
void pre_main(){
}
signed main(){
#ifdef LOCAL
auto start_time = chrono::high_resolution_clock::now();
#endif
if (!interactive) ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
fastio(".inp", ".out");
#endif
int t = 1;
if (multitest) cin >> t;
pre_main();
while (t--) main_program();
#ifdef LOCAL
auto end_time = chrono::high_resolution_clock::now();
double duration = chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count();
cout << "\n[" << duration << "ms]\n";
#endif
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |