Advertisement
Korotkodul

LSD_v2

Oct 1st, 2023
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 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<vector<string>> MergeSort(vector<vector<string>> ar, int par) {
  17.   int len = ar.size();
  18.   if (len == 1) {
  19.     return ar;
  20.   }
  21.   vector<vector<string>> lt;
  22.   vector<vector<string>> 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<vector<string>> 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. string Bin(ll num) {
  59.     string st = "";
  60.     while (num > 0) {
  61.       st += std::to_string(num % 2);
  62.       num /= 2;
  63.     }
  64.     while ((int)st.size() < 64) {
  65.       st += '0';
  66.     }
  67.     return st;
  68. }
  69.  
  70. vector<string> Get(string st) {
  71.   vector<string> res;
  72.   for (int id = 0; id < 64; id += 8) {
  73.     string add = st.substr(id, 8);
  74.     res.push_back(add);
  75.   }
  76.   return res;
  77. }
  78.  
  79.  
  80. int main() {
  81.   std::ios::sync_with_stdio(false);
  82.   std::cin.tie(0);
  83.   std::cout.tie(0);
  84.   ll k;
  85.   cin >> k;
  86.   string st = Bin(k);
  87.   cout << st << "\n";
  88.   /*int len;
  89.   cin >> len;
  90.   vector<vector<string>> ar;
  91.   for (int id = 0; id < len; ++id) {
  92.     ll num; cin >> num;
  93.     string st = Bin(num);
  94.     vector<string> vec = Get(st);
  95.     ar.push_back(vec);
  96.   }
  97.   vector<ll>res*/
  98. }
  99. /*
  100. 9223372036854775807
  101. */
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement