Advertisement
a53

Permutari4

a53
May 19th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. ifstream fin("permutari4.in");
  6. ofstream fout("permutari4.out");
  7.  
  8. const int maxn=1e5+2;
  9. int n, x, res, pos[maxn];
  10.  
  11. int main()
  12. {
  13. fin>>n;
  14. for(int i=1; i<=n; i++)
  15. {
  16. fin>>x;
  17. pos[x]=i;
  18. }
  19. int st=pos[1], dr=pos[1];
  20. res=1;
  21. for(int i=2; i<=n; i++)
  22. {
  23. st=min(st,pos[i]);
  24. dr=max(dr,pos[i]);
  25. if(dr-st+1==i)
  26. {
  27. res++;
  28. }
  29. }
  30. fout<<res<<'\n';
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement