# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
626860 |
2022-08-11T21:58:52 Z |
chonka |
Swap (BOI16_swap) |
C++17 |
|
1000 ms |
9684 KB |
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 2e5 + 7 ;
int n ;
int a[ MAXN ] , ans[ MAXN ] , pos[ MAXN ] ;
bool used[ MAXN ] , right[ MAXN ] ;
set < int > s[ MAXN ] ;
void solve ( ) {
cin >> n ;
for ( int i = 1 ; i <= n ; ++ i ) {
cin >> a[ i ] ;
pos[ a[ i ] ] = i ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
s[ i ].insert ( a[ i ] ) ;
if ( 2 * i <= n ) {
s[ i ].insert ( a[ 2 * i ] ) ;
}
if ( 2 * i + 1 <= n ) {
s[ i ].insert ( a[ 2 * i + 1 ] ) ;
}
}
for ( int i = 1 ; i <= n ; ++ i ) {
int act = 0 ;
while ( 1 ) {
act = *s[ i ].begin ( ) ;
s[ i ].erase ( act ) ;
if ( used[ act ] == false ) { break ; }
}
ans[ i ] = act ;
used[ act ] = true ;
if ( pos[ act ] == 2 * i ) {
s[ 2 * i ].erase ( act ) ;
}
else if ( pos[ act ] == 2 * i + 1 ) {
for ( auto x : s[ i ] ) {
s[ 2 * i ].insert ( x ) ;
s[ 2 * i + 1 ].insert ( x ) ;
}
}
}
for ( int i = 1 ; i <= n ; ++ i ) {
cout << ans[ i ] << " " ;
}
cout << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; // cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
9684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
9684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
9684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
9684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
9684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |