Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Counting inversions
- //
- // Created by Panagiotis Hadjicostas on 17/08/2019.
- // Copyright © 2019 Panagiotis Hadjicostas. All rights reserved.
- //
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <map>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n;
- cin>>n;
- int i,j,t;
- int counter=0;
- //vector <int> b;
- map <int,int> a;
- for(i=0;i<n;i++){
- //cin>>a[i];
- cin>>t;
- a[t]++;
- if(i>0){
- //sort(b.begin(),b.end());
- for (std::map<int,int>::iterator it=a.begin(); it!=a.end(); ++it){
- //cout<<it->first<<" "<<it->second<<endl;
- if(it->first>t){
- counter+=it->second;
- }
- }
- }
- //b.push_back(t);
- // cout<<endl;
- }
- cout<<counter<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement