Submission #1316410

#TimeUsernameProblemLanguageResultExecution timeMemory
1316410chybazuziamedians (balkan11_medians)C++20
100 / 100
17 ms3436 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define s second #define f first const int N = 2e6+3; queue <int> pocz, kon; bool uz[N]; void dod( int pop, int nast, int kt ){ while( uz[pocz.front()] ) pocz.pop(); while( uz[kon.front()] ) kon.pop(); if( pop < nast ){ cout << kon.front() << ' '; uz[ kon.front() ] =1; } else if( pop > nast ){ cout << pocz.front() << ' '; uz[ pocz.front() ] =1; } else{ if( kt == 0 ){ cout << pocz.front() << ' '; uz[ pocz.front() ]=1; } else{ cout << kon.front() << ' '; uz[ kon.front() ]=1; } } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll ilewar, nast, alt, pop=0; cin >> alt; ilewar = 2*alt ; ilewar--; for( int i=1; i<=ilewar; ++i ) pocz.push(i); for( int i=ilewar; i>0; --i ) kon.push(i); for( int i=0 ; i<alt; ++i ){ cin >> nast; if( i == 0 ){ cout << nast << ' '; uz[ nast ] = 1; } else{ if( !uz[nast] ){ cout << nast << ' '; uz[ nast ] = 1; } else dod( pop, nast, 0); dod( pop, nast, 1 ); } pop = nast; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...