func_code_string: #include <bits/stdc++.h>   using namespace std;   int c[100005], n, m;   map<int, int> f;   int lowbit(int x) { return x & (-x); }   void add(int x, int j) {     while (x < 100005) {       c[x] += j;       x += lowbit(x);     }   }   int sum(int x) {     int s = 0;     while (x > 0) {       s += c[x];       x -= lowbit(x);     }     return s;   }   struct node {     int id;     int num;   } a[100005];   bool cmp_id(node A, node B) { return A.id < B.id; }   bool cmp_num(node A, node B) { return A.num < B.num; }   int main() {     int i, j, k, m, cnt, ans, tem;     while (scanf( %d , &n) != EOF) {       f.clear();       cnt = 1;       ans = 0;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i].num);         a[i].id = i;       }       sort(a + 1, a + 1 + n, cmp_num);       for (i = 1; i <= n; i++)         if (f[a[i].num] == 0) f[a[i].num] = cnt++;       sort(a + 1, a + 1 + n, cmp_id);       for (i = 1; i <= n; i++) a[i].num = f[a[i].num];       for (i = 1; i <= n; i++) add(a[i].num, 1);       for (i = n; i >= 1; i--) {         tem = sum(a[i].num);         add(a[i].num, -1);         if (tem == i)           ans++;         else {           int ant = a[i].num;           while (i--) {             ant = min(a[i].num, ant);             int tp = sum(ant);             add(a[i].num, -1);             if (sum(ant) == i - 1) break;           }           ans++;         }       }       printf( %d n , ans);     }     return 0;   }   