fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=1e6;
  5. const int MaxA=1e9;
  6. int N;
  7. int num[MaxN];
  8. int pos[MaxN];
  9. bool comp(int lhs, int rhs){
  10. return (num[lhs]!=num[rhs])? num[lhs]<num[rhs] : lhs<rhs;
  11. }
  12. int main() {
  13. ios::sync_with_stdio(0);
  14. cin.tie(0);cout.tie(0);
  15.  
  16. cin>>N;
  17. for(int n=0;n<N;n++)
  18. cin>>num[n];
  19. iota(pos,pos+N,0);
  20. sort(pos,pos+N,comp);
  21. int ans=0;
  22. int pvt=-1;
  23. for(int n=0;n<N;n++){
  24. pvt=max(pvt,pos[n]);
  25. ans+=n==pvt;
  26. }
  27. cout<<ans;
  28. return 0;
  29. }
Success #stdin #stdout 0s 5708KB
stdin
5
3 2 1 5 4
stdout
2