fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. //common file for PBDS
  4. #include<ext/pb_ds/assoc_container.hpp>
  5. //including tree_order_statistics_node_update
  6. #include<ext/pb_ds/tree_policy.hpp>
  7. //namespace
  8. using namespace __gnu_pbds;
  9.  
  10. //macro definition
  11. #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
  12. int main(){
  13.  
  14. //ordered set
  15. ordered_set st;
  16. //insert operation
  17. st.insert(5);
  18. st.insert(10);
  19. st.insert(1);
  20. st.insert(3);
  21. //st-> {1, 3, 5, 10}
  22.  
  23. //find_by_order() return the iterator to the element at xth(0-based) position
  24. cout<<*(st.find_by_order(2));
  25. cout<<endl;
  26.  
  27. //order_of_key() returns number of elements in set which are strictly less than x
  28. cout<<st.order_of_key(6);
  29. cout<<endl;
  30. st.insert(6);
  31.  
  32. cout<<st.order_of_key(6);
  33. cout<<endl;
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 4460KB
stdin
Standard input is empty
stdout
5
3
3