Submission #1171954

#TimeUsernameProblemLanguageResultExecution timeMemory
1171954nuutsnoyntonmedians (balkan11_medians)C++20
5 / 100
54 ms32580 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll N = 2e5 + 2; set < ll > uragsh_ind[N] , aragsh_ind[N] ; ll uragsh[N] = {0}, aragsh[N] = {0}, a[N] = {0}, b[N] = {0}, used[N] = {0}; int main() { ll n, m, r, x,s, y, i, j,ind, ans, t; cin >> n; for (i = 1; i <= n; i ++) { cin >> a[i]; used[a[i]] = 1; } for (i = 1; i <= 2 * n - 1; i ++) b[i]= -1; b[1] = a[1]; for (i = 2; i <= n; i ++) { if ( a[i] == a[i - 1]) { uragsh[a[i]] = aragsh[a[i]] = 1; uragsh_ind[a[i]].insert(i); aragsh_ind[a[i]].insert(-i); } else { if ( a[i] > a[i- 1]) { aragsh_ind[a[i]].insert(-i); aragsh[a[i]] =1; b[2 * i - 1] = a[i]; } else { uragsh_ind[a[i]].insert(i); uragsh[a[i]] = 1; b[2 * i - 1] = a[i]; } } } queue < ll > q; for (i =1 ; i <= 2 *n - 1; i ++) { if ( used[i] == 1) { for ( ll ind : uragsh_ind[i]) { s = q.front(); q.pop(); b[ind * 2 - 2] = s; } } else { q.push(i); } } queue < ll > v; for (i = 2 * n - 1; i >= 1; i --) { if ( used[i] == 1) { for ( ll ind : aragsh_ind[i]) { s = v.front(); v.pop(); ind =-ind; if ( b[ind * 2 - 1] == -1) b[ind * 2 - 1] = s; else b[ind * 2 - 2] = s; } } else v.push(i); } for (i = 1; i <= 2 *n - 1; i ++) { cout << b[i] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...