Submission #361818

#TimeUsernameProblemLanguageResultExecution timeMemory
361818LawlietMoney (IZhO17_money)C++17
100 / 100
1281 ms51436 KiB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

const int MAXN = 1000010;
const int INF = 1000000010;

int n;

int v[MAXN];

set<int> s;

void solveTestCase()
{
	scanf("%d",&n);

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

	int ans = 1, opt = 1;
	int Lvalue = v[1], Rvalue = INF;

	for(int i = 2 ; i <= n ; i++)
	{
		if( v[i - 1] > v[i] )
		{
			while( opt < i )
				s.insert( v[opt++] );
		}

		if( opt != i && v[i] <= Rvalue ) continue;	

		ans++;

		auto it = s.upper_bound( v[i] );

		if( it == s.end() ) Rvalue = INF;
		else Rvalue = *it;

		if( it == s.begin() ) Lvalue = -INF;
		else it--, Lvalue = *it;
	}

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

int main()
{
	int t = 1;
	// scanf("%d",&t);

	while( t-- )
		solveTestCase();
}

Compilation message (stderr)

money.cpp: In function 'void solveTestCase()':
money.cpp:24:6: warning: variable 'Lvalue' set but not used [-Wunused-but-set-variable]
   24 |  int Lvalue = v[1], Rvalue = INF;
      |      ^~~~~~
money.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
money.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   scanf("%d",&v[i]);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...