Submission #39712

#TimeUsernameProblemLanguageResultExecution timeMemory
39712MladenPmedians (balkan11_medians)C++14
100 / 100
73 ms2600 KiB
#include<bits/stdc++.h> #define STIZE(x) fprintf(stderr, "STIZE%d\n", x); #define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x); #define NL(x) printf("%c", " \n"[(x)]); #define lld long long #define pii pair<int,int> #define pb push_back #define fi first #define se second #define endl '\n' #define mid (l+r)/2 #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 100010 int n, b[MAXN], l, r; bool pos[2*MAXN]; void upd() { while(l < r && pos[l]) l++; while(l < r && pos[r]) r--; } int main() { //ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) cin >> b[i]; l = 1, r = 2*n-1, pos[b[1]] = 1; cout << b[1] << ' '; for(int i = 2; i <= n; i++) { upd(); if(b[i] == b[i-1]) { pos[l] = pos[r] = 1; cout << l << ' ' << r << ' '; } else if(b[i] > b[i-1]) { if(pos[b[i]]) { cout << r << ' '; pos[r] = 1; upd(); cout << r << ' '; pos[r] = 1; } else { pos[b[i]] = pos[r] = 1; cout << b[i] << ' ' << r << ' '; } } else { if(pos[b[i]]) { cout << l << ' '; pos[l] = 1; upd(); cout << l << ' '; pos[l] = 1; } else { pos[b[i]] = pos[l] = 1; cout << b[i] << ' ' << l << ' '; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...