fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. template <class K> using mset = __gnu_pbds::tree<K, __gnu_pbds::null_type, less_equal<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
  5. mset<int> ms; //multiset
  6. int main() {
  7. ms.insert(-1);
  8. ms.insert(1);
  9. ms.insert(1);
  10. ms.insert(3);
  11. ms.insert(3);
  12. ms.insert(5);
  13. ms.insert(5);
  14. //ms.order_of_key(x) = # of values < x
  15. cout << ms.order_of_key(1) << endl; //# values < 1
  16. cout << ms.order_of_key(3) << endl; //# values < 3
  17. cout << ms.order_of_key(5) << endl; //# values < 5
  18. cout << ms.order_of_key(6) << endl; //# values < 6
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5476KB
stdin
Standard input is empty
stdout
1
3
5
7