fork download
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. typedef __gnu_pbds::tree<
  8. int,
  9. __gnu_pbds::null_type,
  10. less<>,
  11. __gnu_pbds::rb_tree_tag,
  12. __gnu_pbds::tree_order_statistics_node_update>
  13. ordered_set;
  14.  
  15. int main() {
  16. ordered_set X;
  17. for(int i = 1; i<1024; i += i) {
  18. X.insert(i);
  19. }
  20.  
  21. cout << "Order of key " << endl;
  22. for(int i = 1; i<1024; i += i) {
  23. cout << X.order_of_key(i) << " ";
  24. }
  25.  
  26. cout << endl << "Get by order " << endl;
  27.  
  28. for(int i = 0; i < 10; ++i) {
  29. cout << *X.find_by_order(i) << " ";
  30. }
  31.  
  32. cout << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4364KB
stdin
Standard input is empty
stdout
Order of key 
0 1 2 3 4 5 6 7 8 9 
Get by order 
1 2 4 8 16 32 64 128 256 512