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