Submission #244616

#TimeUsernameProblemLanguageResultExecution timeMemory
244616Nightlightmedians (balkan11_medians)C++14
100 / 100
38 ms3320 KiB
#include <bits/stdc++.h> #define pii pair<long double, int> using namespace std; int N; bool vis[200005]; int A[200005]; int mn, mx; int p; void addmn() { while(vis[mn] == 1) mn++; vis[mn] = 1; A[++p] = mn; } void addmx() { while(vis[mx] == 1) mx--; vis[mx] = 1; A[++p] = mx; } int main() { ios_base::sync_with_stdio(0); cin >> N; cin >> A[1]; int bef = A[1], now; vis[A[1]] = 1; mn = 1, mx = N * 2 - 1; p = 1; for(int i = 2; i <= N; i++) { cin >> now; if(now > bef) { if(vis[now]) { addmx(); addmx(); }else { vis[now] = 1; A[++p] = now; addmx(); } }else if(now < bef) { if(vis[now]) { addmn(); addmn(); }else { vis[now] = 1; A[++p] = now; addmn(); } }else { addmx(); addmn(); } bef = now; } for(int i = 1; i <= p; i++) { cout << A[i] << " "; } cin >> N; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...