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 in freopen ("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long int
const int val = (1e6) + 5;
const int inf = (1e6);
double eps = 0.000000001;
using namespace std;
int a[val], d[val];
void update(int x){
    while(x <= inf){
        d[x] += 1;
        x += (x & -x);
    }
}
int get(int x){
    int s = 0;
    while(x > 0){
        s += d[x];
        x -= (x & -x);
    }
    return s;
}
int solve(){
    int n;
    cin >> n;
    for(int i=1; i<=n; ++i){
        cin >> a[i];
    }
    int x = inf, ans = 1;
    update(a[1]);
    update(inf);
    for(int i=2; i<=n; ++i){
        if(a[i] >= a[i-1] && a[i] <= x){
            update(a[i]);
        }
        else{
            int l = a[i], r = inf;
            while(l < r){
                int m = (l + r) / 2;
                if(get(m) > get(a[i])){
                    r = m;
                }
                else{
                    l = m + 1;
                }
            }
            x = l;
            update(a[i]);
            ++ ans;
        }
    }
    cout << ans << endl;
}
int main(){
    //in out
	ios_base::sync_with_stdio(0);
    solve();
    return 0;
}
Compilation message (stderr)
money.cpp: In function 'int solve()':
money.cpp:60:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
| # | 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... |