Advertisement
Korotkodul

LSD

Oct 1st, 2023 (edited)
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::max;
  9. using std::min;
  10. using std::string;
  11. using std::vector;
  12. using ll = long long;
  13.  
  14. int inv = 0;
  15.  
  16. vector<int> MergeSort(vector<vector<string>> ar, int par) {
  17.   int len = ar.size();
  18.   if (len == 1) {
  19.     return ar;
  20.   }
  21.   vector<int> lt;
  22.   vector<int> rt;
  23.   for (int id = 0; id < len / 2; ++id) {
  24.     lt.push_back(ar[id]);
  25.   }
  26.   for (int id = len / 2; id < len; ++id) {
  27.     rt.push_back(ar[id]);
  28.   }
  29.   lt = MergeSort(lt, par);
  30.   rt = MergeSort(rt, par);
  31.   int ln = lt.size();
  32.   int rn = rt.size();
  33.   int lid = 0;
  34.   int rid = 0;
  35.   vector<int> res;
  36.   while (lid < ln || rid < rn) {
  37.     if (lid < ln && rid < rn) {
  38.       if (lt[lid][par] <= rt[rid][par]) {
  39.         res.push_back(lt[lid]);
  40.         lid++;
  41.       } else {
  42.         res.push_back(rt[rid]);
  43.         rid++;
  44.         inv += ln - lid;
  45.       }
  46.     } else if (lid < ln) {
  47.       res.push_back(lt[lid]);
  48.       lid++;
  49.  
  50.     } else if (rid < rn) {
  51.       res.push_back(rt[rid]);
  52.       rid++;
  53.     }
  54.   }
  55.   return res;
  56. }
  57.  
  58.  
  59.  
  60. int main() {
  61.   std::ios::sync_with_stdio(false);
  62.   std::cin.tie(0);
  63.   std::cout.tie(0);
  64.   int len;
  65.   cin >> len;
  66.   vector<vector<string>> ar;
  67.   for (int id = 0; id < len; ++id) {
  68.     ll num; cin >> num;
  69.     string st = Bin(num);
  70.     vector<string> vec = Get(st);
  71.     ar.push_back(vec);
  72.   }
  73.   vector<ll>res
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement