fork(1) 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. typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
  8.  
  9.  
  10. int main() {
  11. indexed_multiset ms;
  12. vector<int> v{1, 1, 2, 2, 3, 4, 5, 6, 6};
  13.  
  14. for(int i : v) ms.insert(i);
  15.  
  16. cout << "Ordered Multiset: ";
  17. for(auto x : ms) cout << x << ' '; cout << '\n';
  18.  
  19. cout << "Lower bound of 2: " << *ms.lower_bound(2) << '\n';
  20. cout << "Upper bound of 2: " << *ms.upper_bound(2) << '\n';
  21.  
  22. if (ms.find(6) != ms.end()) {
  23. ms.erase(6);
  24. ms.insert(4);
  25. }
  26.  
  27. cout << "Ordered Multiset: ";
  28. for(auto x : ms) cout << x << ' '; cout << '\n';
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
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
Ordered Multiset: 1 1 2 2 3 4 5 6 6