Advertisement
LEGEND2004

ordered_set , ordered_multiset

Nov 11th, 2023
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace std;
  4. using namespace __gnu_pbds;
  5.  
  6. #define int long long
  7. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  8. typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
  9.  
  10. signed main()
  11. {
  12.     ordered_multiset s;
  13.     s.insert(2);
  14.     s.insert(7);
  15.     s.insert(5);
  16.     s.insert(2);
  17.     //i - th
  18.     for(auto i : s)
  19.         cout << i << " ";
  20.     cout << endl;
  21.     int i = 2;
  22.     auto it = s.begin();
  23.     while(i--){
  24.         it++;
  25.     }
  26.     cout << *it << endl;
  27.     i = 2;
  28.     cout << *s.find_by_order(i) << endl; // iterator i-th place
  29.  
  30.     int x = 5;
  31.     cout << distance(s.begin() , s.lower_bound(x)) << endl;
  32.     int cnt = 0;
  33.     it = s.lower_bound(x);
  34.     while(it != s.begin()){
  35.         cnt++;
  36.         it--;
  37.     }
  38.     cout << cnt << endl;
  39.  
  40.     cout << s.order_of_key(x) << endl; // s.lower_bound(x) - s.begin()
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement