Submission #1171967

#TimeUsernameProblemLanguageResultExecution timeMemory
1171967nuutsnoyntonmedians (balkan11_medians)C++20
35 / 100
57 ms34116 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll N = 2e5 + 2; multiset < ll > uragsh_ind[N], aragsh_ind[N]; ll uragsh[N], aragsh[N], a[N], b[N], 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]; } for (i = 1; i <= 2 * n - 1; i ++) b[i]= -1; b[1] = a[1]; used[a[1]] = 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; if( used[a[i]] == 0) { b[2 * i - 1] = a[i]; } else aragsh_ind[a[i]].insert(-i); } else { uragsh_ind[a[i]].insert(i); uragsh[a[i]] = 1; if ( used[a[i]] == 0) { b[2 * i - 1] = a[i]; } else uragsh_ind[a[i]].insert(i); } used[a[i]] = 1; } } 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(); if ( b[ind * 2 - 1] == -1) b[ind * 2 - 1] = s; else b[ind * 2 - 2] = s; } } else { q.push(i); } } stack < ll > v; while(!q.empty()) { v.push(q.front()); q.pop(); } for (i = 2 * n - 1; i >= 1; i --) { if ( used[i] == 1) { for ( ll ind : aragsh_ind[i]) { s = v.top(); v.pop(); ind =-ind; if ( b[ind * 2 - 1] == -1) b[ind * 2 - 1] = s; else b[ind * 2 - 2] = s; } } } for (i = 1; i <= 2 *n - 1; i ++) { cout << b[i] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...