fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define endl "\n"
  4. using namespace std;
  5. int n,i,a[200001],kq=1; map<int,int> mp;
  6. signed main()
  7. {
  8. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9. cin>>n;
  10. for(i=1;i<=n;i++)
  11. {
  12. cin>>a[i]; mp[a[i]]=i;
  13. }
  14. sort(a+1,a+n+1);
  15. for(i=1;i<n;i++)
  16. {
  17. if (mp[a[i]]>mp[a[i+1]]) kq++;
  18. }
  19. cout<<kq;
  20. }
Success #stdin #stdout 0.01s 5312KB
stdin
5
4 2 1 5 3
stdout
3