Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // Counting inversions
  4. //
  5. // Created by Panagiotis Hadjicostas on 17/08/2019.
  6. // Copyright © 2019 Panagiotis Hadjicostas. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <map>
  13. using namespace std;
  14. int main() {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(NULL);
  17. int n;
  18.  
  19. cin>>n;
  20.  
  21. int i,j,t;
  22. int counter=0;
  23. //vector <int> b;
  24.  
  25. map <int,int> a;
  26. for(i=0;i<n;i++){
  27. //cin>>a[i];
  28. cin>>t;
  29. a[t]++;
  30. if(i>0){
  31. //sort(b.begin(),b.end());
  32. for (std::map<int,int>::iterator it=a.begin(); it!=a.end(); ++it){
  33. //cout<<it->first<<" "<<it->second<<endl;
  34. if(it->first>t){
  35. counter+=it->second;
  36. }
  37. }
  38.  
  39.  
  40. }
  41. //b.push_back(t);
  42. // cout<<endl;
  43. }
  44.  
  45. cout<<counter<<endl;
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement