Advertisement
Imran_Mohammed

using pbs

Feb 9th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. // In The Name Of Allah
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. using namespace __gnu_pbds;
  8.  
  9. typedef tree< long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
  10.  
  11. int main(){
  12.  
  13. //input number:
  14. ordered_set pbs;
  15. pbs.insert(1);
  16. pbs.insert(3);
  17. pbs.insert(3);
  18. pbs.insert(2);
  19. cout <<pbs.size() << endl;//4
  20. for(auto u : pbs)cout << u << " ";//1` 2 3 3
  21. cout << endl;
  22.  
  23. /// cout<<X.order_of_key(-5)<<endl;  // number of items in a set that are strictly smaller than our item
  24. ordered_set pbs;
  25. pbs.insert(1);
  26. pbs.insert(3);
  27. pbs.insert(3);
  28. pbs.insert(2);
  29. pbs.insert(7);
  30. cout << pbs.order_of_key(6) << endl;//4
  31.  
  32. /// cout<<*X.find_by_order(1)<<endl; // iterator to the k-th largest element
  33. ordered_set pbs;
  34. pbs.insert(1);
  35. pbs.insert(3);
  36. pbs.insert(3);
  37. pbs.insert(2);
  38. pbs.insert(7);
  39. cout << *pbs.find_by_order(4) << endl;//7
  40.  
  41. //Lower bound , Upper bound(upper is to lower,lower is to upper)
  42. ordered_set pbs;
  43. pbs.insert(1);
  44. pbs.insert(2);
  45. pbs.insert(3);
  46. pbs.insert(4);
  47. pbs.insert(5);
  48. pbs.insert(6);
  49. cout << *pbs.lower_bound(3) << endl;//4
  50. cout << *pbs.upper_bound(3) << endl;//3
  51.  
  52. //basic rule:
  53. ordered_set pbs;
  54.  
  55. ///Insert a number
  56. pbs.insert(2);
  57. ///delete a given number
  58. pbs.erase(2);
  59. ///chek is the list is empty
  60. if(pbs.empty());
  61. ///cout of given number
  62. pbs.count(2);
  63. ///deletye all the number
  64. pbs.clear();
  65. ///how many distinct number
  66. pbs.size();
  67. ///what is smallest number
  68. *pbs.begin();
  69. ///what is greatest number
  70. *pbs.rbegin();
  71. ///find number
  72. if(pbs.find());
  73. ///how many numbers are smaller
  74. pbs.order_of_key(4);
  75. ///delete k-th smallest number
  76. pbs.erase( pbs.find_by_order(4));
  77. ///print number in ascending order
  78. for(int i=pbs.begin(); i!=pbs.end(), i++)
  79.    
  80. return 0;
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement