Submission #1268289


Source Code Expand

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 200020;

int q[MAXN], p[MAXN], n, T[MAXN], f[MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) q[ p[ i ] = read() ] = i;
	for( int i = n - 1 ; i ; i-- )
	{
		if( !T[ i + 1 ] )
		{
			if( q[ i ] > q[ i + 1 ] ) T[ i ] = 1, f[ i ] = i + 1;
			else T[ i ] = 0;
		}
		else
		{
			int cnt = 0;
			cnt += q[ f[ i + 1 ] ] < q[ i ];
			cnt += q[ i ] < q[ i + 1 ];
			cnt += q[ i + 1 ] < q[ f[ i + 1 ] ];
			if( cnt == 2 ) T[ i ] = T[ i + 1 ], f[ i ] = f[ i + 1 ];
			else T[ i ] = T[ i + 1 ] + 1, f[ i ] = i + 1;
		}
	}
	return printf( "%d\n", T[ 1 ] ), 0;
}

Submission Info

Submission Time
Task F - Strange Sorting
User wxh010910
Language C++14 (GCC 5.4.1)
Score 2400
Code Size 1191 Byte
Status AC
Exec Time 15 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2400 / 2400
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 14 ms 3328 KB
in10.txt AC 14 ms 3328 KB
in11.txt AC 14 ms 3328 KB
in12.txt AC 14 ms 3328 KB
in13.txt AC 14 ms 3328 KB
in14.txt AC 14 ms 3328 KB
in15.txt AC 15 ms 3328 KB
in16.txt AC 15 ms 3328 KB
in17.txt AC 15 ms 3328 KB
in18.txt AC 14 ms 3328 KB
in19.txt AC 15 ms 3328 KB
in2.txt AC 15 ms 3328 KB
in20.txt AC 14 ms 3328 KB
in21.txt AC 12 ms 2560 KB
in22.txt AC 13 ms 3328 KB
in23.txt AC 1 ms 256 KB
in3.txt AC 14 ms 3328 KB
in4.txt AC 15 ms 3328 KB
in5.txt AC 14 ms 3328 KB
in6.txt AC 14 ms 3328 KB
in7.txt AC 14 ms 3328 KB
in8.txt AC 15 ms 3328 KB
in9.txt AC 14 ms 3328 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB