Submission #710153

#TimeUsernameProblemLanguageResultExecution timeMemory
710153hpesojMoney (IZhO17_money)C++17
100 / 100
1008 ms55128 KiB
#include <bits/stdc++.h>
#define int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << '\n'
using namespace std;
const int inf = 1000000000;
int n, a[1000005];
set <int> s;
signed main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	s.insert(a[1]);
	int l = 2;
	while(l <= n and a[l] >= a[l-1]){
		s.insert(a[l]);
		l++;
	}
	if(l > n){
		cout << 1;
		return 0;
	}
	//for(int i = 1; i < l; i++) cout << a[i] << ' ';
	int i = l, ans = 1;
	for(; i <= n; i++){
		if(i == l) continue;
		auto it = s.upper_bound(a[l]);
		if(a[i] < a[i-1] or (it != s.end() and *it < a[i])){
			ans++;
			for(int j = l; j < i; j++) s.insert(a[j]);
			l = i;
		}
	}
	ans++;
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...