ProgMe

Untitled

Feb 12th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <bits/extc++.h>
  3. #include <tr2/dynamic_bitset>
  4.  
  5. #define int int64_t
  6.  
  7. using namespace std;
  8. using namespace __gnu_pbds;
  9. using namespace __gnu_cxx;
  10.  
  11. typedef std::tr2::dynamic_bitset<> bitvector;
  12.  
  13. template<typename T>
  14. using or_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
  15.  
  16. template<typename T>
  17. using or_multiset = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;
  18.  
  19. int g_sort(vector<int> &a){
  20. int cnt = 0;
  21. while(true){
  22. pair<int, int> fnd = {-1, -1};
  23. for(int i = 0; i < a.size() - 1; i++)
  24. for(int j = i + 1; j < a.size(); j++)
  25. if(a[i] > a[j] && (fnd.second == -1 || a[i] - a[j] > a[fnd.first] - a[fnd.second]))
  26. fnd.first = i, fnd.second = j;
  27. if(fnd.first == fnd.second)
  28. break;
  29. swap(a[fnd.first], a[fnd.second]);
  30. cnt++;
  31. }
  32. return cnt;
  33. }
  34.  
  35. void solve(){
  36. vector<int> a = {12,7,18,2,9,11,4,5,19,8,0,15,13,1,10,3,14,6,17,16};
  37. cout << g_sort(a);
  38. }
  39.  
  40. int32_t main() {
  41. int test_case = 1;
  42. //cin >> test_case;
  43. while(test_case--)
  44. solve();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment