Advertisement
_ash__

Untitled

Aug 22nd, 2020
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. typedef
  8. tree < int, null_type ,less<int>,
  9. rb_tree_tag,
  10. tree_order_statistics_node_update > ordered_set;
  11.  
  12. /*
  13.     Operations :
  14.     find_by_order : returns an iterator to the k-th
  15.     largest element (counting from zero).
  16.     order_of_key :  returns the number of items in
  17.     a set that are strictly smaller than our item.
  18.     # to use as a multiset just insert a pair<int,int> with unique second element, change
  19.     int to pair<int,int> in typedef part
  20. */
  21.  
  22.  
  23. ordered_set Set;
  24.  
  25.  
  26. int main() {
  27.  
  28.     Set.insert(5);
  29.     Set.insert(2);
  30.     Set.insert(6);
  31.     Set.insert(5);
  32.     cout << Set.order_of_key(2) << endl;
  33.     cout << Set.size() << endl;
  34.     auto it = Set.find_by_order(2); /// iterator to the 3th number
  35.     cout << *it << endl;
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement