EzicMan

Haar

Feb 7th, 2019
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. cout << "l=" << l << " r=" << r << endl;
  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. cout << i << " " << j << " " << x << " " << endl;
  27. for(ll i = 0; i < a.size(); i++){
  28. cout << a[i] << " ";
  29. }
  30. cout << endl;
  31. i++;
  32. j--;
  33. }
  34. }
  35. Haar(l,j);
  36. Haar(j+1,r);
  37. }
  38.  
  39. int main(){
  40. srand(time(0));
  41. ll n;
  42. cin >> n;
  43. a.resize(n);
  44. for(ll i = 0; i < n; i++){
  45. a[i] = rand() % 10000 + 1;
  46. }
  47. Haar(0,a.size()-1);
  48. for(ll i = 0; i < n-1; i++){
  49. cout << a[i] << " ";
  50. }
  51. cout << endl;
  52. for(ll i = 0; i < n-1; i++){
  53. if(a[i] > a[i+1]){
  54. cout << i << endl;
  55. cout << a[i] << " " << a[i+1] << endl;
  56. cout << "NO";
  57. return 0;
  58. }
  59. }
  60. cout << "YES";
  61. return 0;
  62. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×