# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
621107 | 2022-08-03T12:22:42 Z | mdn2002 | Sorting (IOI15_sorting) | C++14 | 5 ms | 468 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; int n , m , a [200005] , aa [200005] , x [600005] , y [600005] , dis [200005] , wrdis [200005] , wra [200005]; bool ck ( int xx ) { for ( int i = 1 ; i <= n ; i ++ ) { a [i] = aa [i]; wra [ a [i] ] = i; } int mm = xx; for ( int i = 1 ; i <= n ; i ++ ) { dis [i] = i; wrdis [ dis [i] ] = i; } for ( int j = mm - 1 ; j >= 0 ; j -- ) { swap ( dis [ x [j] ] , dis [ y [j] ] ); swap ( wrdis [ dis [ x [j] ] ] , wrdis [ dis [ y [j] ] ] ); } set < int > dq; for ( int i = 1 ; i <= n ; i ++ ) { if ( dis [i] != a [i] ) dq . insert ( dis [i] ); } for ( int i = 1 ; i <= mm ; i ++ ) { if ( dq . size () == 0 ) return 1; swap ( a [ x [ i - 1 ] ] , a [ y [ i - 1 ] ] ); swap ( dis [ x [ i - 1 ] ] , dis [ y [ i - 1 ] ] ); swap ( wrdis [ dis [ x [ i - 1 ] ] ] , wrdis [ dis [ y [ i - 1 ] ] ] ); swap ( wra [ a [ x [ i - 1 ] ] ] , wra [ a [ y [ i - 1 ] ] ] ); int x = * dq . begin (); dq . erase ( dq . begin () ); int j = wrdis [x]; int y = wra [x]; swap ( a [j] , a [y] ); swap ( wra [ a [j] ] , wra [ a [y] ] ); if ( dis [y] == a [y] ) dq . erase ( dq . lower_bound ( y ) ); } if ( dq . size () == 0 ) return 1; return 0; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = N; for ( int i = 1 ; i <= n ; i ++ ) { a [i] = S [ i - 1 ]; a [i] ++; aa [i] = a [i]; } m = M; for ( int i = 0 ; i < m ; i ++ ) { x [i] = X [i] , y [i] = Y [i]; x [i] ++ , y [i] ++; } int l = 0 , r = m + 1 , mid; while ( l < r ) { mid = ( l + r ) / 2; if ( ck ( mid ) ) r = mid; else l = mid + 1; } m = l; int rr = 0; for ( int i = 1 ; i <= n ; i ++ ) { a [i] = aa [i]; wra [ a [i] ] = i; } for ( int i = 1 ; i <= n ; i ++ ) { dis [i] = i; wrdis [ dis [i] ] = i; } for ( int j = m - 1 ; j >= 0 ; j -- ) { swap ( dis [ x [j] ] , dis [ y [j] ] ); swap ( wrdis [ dis [ x [j] ] ] , wrdis [ dis [ y [j] ] ] ); } set < int > dq; for ( int i = 1 ; i <= n ; i ++ ) { if ( dis [i] != a [i] ) dq . insert ( dis [i] ); } for ( int i = 1 ; i <= m ; i ++ ) { if ( dq . size () == 0 ) return 1; swap ( a [ x [ i - 1 ] ] , a [ y [ i - 1 ] ] ); swap ( dis [ x [ i - 1 ] ] , dis [ y [ i - 1 ] ] ); swap ( wrdis [ dis [ x [ i - 1 ] ] ] , wrdis [ dis [ y [ i - 1 ] ] ] ); swap ( wra [ a [ x [ i - 1 ] ] ] , wra [ a [ y [ i - 1 ] ] ] ); int x = * dq . begin (); dq . erase ( dq . begin () ); int j = wrdis [x]; int y = wra [x]; swap ( a [j] , a [y] ); swap ( wra [ a [j] ] , wra [ a [y] ] ); P [ i - 1 ] = j - 1 , Q [ i - 1 ] = y - 1; if ( dis [y] == a [y] ) dq . erase ( dq . lower_bound ( y ) ); } return rr; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Incorrect | 0 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Incorrect | 0 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Incorrect | 0 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Incorrect | 0 ms | 340 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |