답안 #229841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229841 2020-05-06T19:33:21 Z Lawliet Money (IZhO17_money) C++17
0 / 100
4 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000010;

int n;

int L[MAXN];
int R[MAXN];
int v[MAXN];
int ord[MAXN];
int firstOcc[MAXN];

void removeSegment(int A, int B)
{
	R[ L[A] ] = R[A];
	L[ R[B] ] = L[B];
}

int main()
{
	scanf("%d",&n);

	for(int i = 1 ; i <= n ; i++)
	{
		scanf("%d",&v[i]);
		ord[i] = v[i];
	}

	sort( ord + 1 , ord + n + 1 );

	iota( L + 1 , L + n + 1 , 0 );
	iota( R + 1 , R + n + 1 , 2 );

	for(int i = n ; i > 0 ; i--)
		firstOcc[ ord[i] ] = i;

	int ans = 0;
	int last = n;

	while( last > 0 )
	{
		ans++;

		int p = last;
		int aux = last;

		while( p > 0 && v[p] == v[last] )
			p--;

		if( p == 0 ) break;

		int curInd = firstOcc[ v[last] ];
		firstOcc[ v[last] ] = curInd + last - p;

		last = p;

		for(int i = p ; i > 0 ; i--)
		{
			if( v[i] != ord[ L[curInd] ] )
				break;

			last--;
			curInd = L[curInd];
		}

		removeSegment( last + 1 , aux );
	}

	printf("%d\n",ans);
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
money.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&v[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -