Advertisement
EzicMan

hoarnotworkking

Feb 14th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8.  
  9. vector<ll> a;
  10.  
  11. void Haar(ll l, ll r){
  12. ll i = l, j = r, x = a[(l + r) / 2];
  13.  
  14. if(l >= r){
  15. return;
  16. }
  17. while(i < j){
  18. while(a[i] < x){
  19. i++;
  20. }
  21. while(a[j] > x){
  22. j--;
  23. }
  24. if(i < j){
  25. swap(a[i],a[j]);
  26. i++;
  27. j--;
  28. }
  29. }
  30. cout << i << " " << j << endl;
  31. Haar(l,j);
  32. Haar(j+1,r);
  33. }
  34.  
  35. int main(){
  36. ll n;
  37. srand(time(0));
  38. cin >> n;
  39. a.resize(n);
  40. for(ll i = 0; i < n; i++){
  41. a[i] = rand() % 10 + 1;
  42. }
  43. Haar(0,a.size()-1);
  44. for(ll i = 0; i < n-1; i++){
  45. if(a[i] > a[i+1]){
  46. cout << "WRONG" << endl;
  47. }
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement