SHARE
TWEET

ikvc

sacgajcvs Jul 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     STARK_BOY
  3. */
  4. #include <bits/stdc++.h>
  5. #include <fstream>
  6. using namespace std;
  7. #define rep(i,a,b) for(ll i=a;i<b;i++)
  8. #define F first
  9. #define S second
  10. typedef long long ll;
  11. typedef vector< ll > vi;
  12. #include<ext/pb_ds/assoc_container.hpp>
  13. #include<ext/pb_ds/tree_policy.hpp>
  14. using namespace __gnu_pbds;
  15. template<typename T>
  16. using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
  17. int main()
  18. {
  19.     int ti=1;
  20.     //cin>>ti;
  21.     while(ti--)
  22.     {
  23.         ll n;
  24.         cin>>n;
  25.         vi ar(n);
  26.         rep(i,0,n)cin>>ar[i];
  27.         map<ll,ll> ma;
  28.         ordered_set<pair<ll,ll>> se;
  29.         ll ans=0;
  30.         for(ll i=n-1;i>=0;i--)
  31.         {
  32.             pair<ll,ll> p=make_pair(ar[i],0);
  33.             ans+=se.order_of_key(p);
  34.             ma[ar[i]]++;
  35.             se.insert(make_pair(ar[i],ma[ar[i]]));
  36.         }
  37.         cout<<ans;      
  38.     }
  39.     return 0;
  40.        
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top