fork download
  1. #include <iostream>
  2. #include<ext/pb_ds/assoc_container.hpp>
  3. #include<ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5.  
  6. using namespace __gnu_pbds;
  7. template <class T>
  8. using indexed_multiset = tree<
  9. T,
  10. null_type,
  11. less_equal<T>,
  12. rb_tree_tag,
  13. tree_order_statistics_node_update
  14. >;
  15.  
  16.  
  17. int main() {
  18. indexed_multiset<int> ms;
  19. vector<int> v{1, 1, 2, 2, 3, 4, 5, 6, 6};
  20.  
  21. for(int i : v) ms.insert(i);
  22.  
  23. cout << "Ordered Multiset: ";
  24. for(auto x : ms) cout << x << ' '; cout << '\n';
  25.  
  26. cout << "Lower bound of 2: " << *ms.lower_bound(2) << '\n';
  27. cout << "Upper bound of 2: " << *ms.upper_bound(2) << '\n';
  28. return 0;
  29. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Ordered Multiset: 1 1 2 2 3 4 5 6 6 
Lower bound of 2: 3
Upper bound of 2: 2