This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define Add_Speed ios_base::sync_with_stdio(0);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define f first
#define sz size()
#define s second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define inf INT_MAX
                                                                                                                                            
using namespace std;
const int maxn = (int)1e6 + 100;
const int maxM = (int)1e3 + 100;
const int mod = (int)1e9 + 7;
const int maxlog = (int)20;
const int P = mod;                  
int n, a[maxn], ans;
set<int> s;
main () {
  Add_Speed
  cin >> n;
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  s.insert(-1);
  s.insert(inf);
  int i = 1;
  while(i <= n){
    ans++;
    int j = i;
    int x = *s.upper_bound(a[i]);
    while(j + 1 <= n && a[j + 1] >= a[j] && a[j + 1] <= x){
      j++;
    }
    for(int k = i; k <= j; k++)
      s.insert(a[k]);
    i = j + 1;
  } 
  cout << ans;
}
Compilation message (stderr)
money.cpp:25:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^| # | 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... |