#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
set<int> s;
int a[1000001];
void solve () {
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
s.insert(1e9);
int l = 0, mx, ans = 0;
while (l < n) {
mx = *s.ub(a[l]);
s.insert(a[l]);
while (l+1 < n && a[l] <= a[l+1] && a[l+1] <= mx) {l++; s.insert(a[l]);}
l++; ans++;
}
cout << ans;
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |