Submission #1316871

#TimeUsernameProblemLanguageResultExecution timeMemory
1316871mpdogemedians (balkan11_medians)C++20
10 / 100
69 ms12040 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> #include <queue> #include <unordered_set> #include <unordered_map> #include <numeric> #include <cmath> // Dla macOs zachowaj includy w przeciwnym wypadku zastąp "#include <bits/stdc++.h> " // szybki kod #define all(v) (v).begin(), (v).end() #define rep(i, a, b) for(int i = a;i <= b; i++) #define per(i, a, b) for(int i = a;i >= b; i--) #define pb push_back #define ins insert #define st first #define nd second #define test int tc; cin>>tc; while(tc--) // struktury danych #define smldi set<map<long double, int > > #define spumldidsi set<pair<unordered_map<long double, int>, deque<set<long long> > > > // funkcje wspomagajace debugowanie programu #define printv(a) { for(auto u : a) cout<<u<<" "; cout<<"/n"; } #define debug(x) cerr << #x << " = " << x << endl; // usingi using namespace std; using ll = long long; using pii = pair<int,int>; using vi = vector<int>; using si = set<int>; using mii = map<int,int>; using bigi = __int128; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,N; cin>>n; N = n*2-1; vector<int> a,b; for(int i=0;i<n;i++){ int c; cin>>c; b.pb(c); } set<int> nie_uzyte; for(int i=1;i<=N;i++){ nie_uzyte.insert(i); } a.resize(N+1); a[0] = b[0]; nie_uzyte.erase(a[0]); for(int i=1;i<n;i++){ if(b[i] == b[i-1]){ a[i*2-1] = *nie_uzyte.begin(); a[i*2] = *nie_uzyte.rbegin(); nie_uzyte.erase(*nie_uzyte.begin()); nie_uzyte.erase(*nie_uzyte.rbegin()); } if(b[i] > b[i-1]){ if(nie_uzyte.find(b[i]) != nie_uzyte.end()){ a[i*2-1] = b[i]; nie_uzyte.erase(b[i]); }else{ a[i*2-1] = *nie_uzyte.upper_bound(b[i-1]); nie_uzyte.erase(nie_uzyte.upper_bound(b[i-1])); } auto it = nie_uzyte.upper_bound(b[i]); a[i*2] = *it; nie_uzyte.erase(*it); } if(b[i] < b[i-1]){ if(nie_uzyte.find(b[i]) != nie_uzyte.end()){ a[i*2-1] = b[i]; nie_uzyte.erase(b[i]); }else{ auto it = nie_uzyte.upper_bound(b[i-1]); it--; a[i*2-1] = *it; nie_uzyte.erase(*it); } auto it = nie_uzyte.upper_bound(b[i]); it--; a[i*2] = *it; nie_uzyte.erase(*it); } } for(int i=0;i<N;i++){ cout<<a[i]<<" "; } cout<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...