fork(4) download
  1. #include <iostream>
  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.  
  8. typedef
  9. tree<
  10. int,
  11. null_type,
  12. less<int>,
  13. rb_tree_tag,
  14. tree_order_statistics_node_update>
  15. set_t;
  16.  
  17. int main()
  18. {
  19. set_t s;
  20. s.insert(12);
  21. s.insert(50);
  22. s.insert(30);
  23. s.insert(20);
  24. cout << "1st element: " << *s.find_by_order(1) << '\n';
  25. cout << "Position of 30: " << s.order_of_key(30) << '\n';
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4424KB
stdin
Standard input is empty
stdout
1st element: 20
Position of 30: 2