We need ADT having search and rank features. That is, in addition to the interface of STL map, a function \'int get_rank(key)\' is required.
Standard implementation
The rank of the given key K is the number of keys which are less or equal to K.
E.g., let set s = {1, 3, 4, 6, 9}. Then rank(1) = 1, rank(4) = 3, rank(9) = 5.
The STL function distance() can be used for computing the rank of an element x appearing in the set s.
rank = distance(s.begin(), s.find(x));
The problem is that its time complexity is O(n).
Note that proposed two maps (or sets) indexed by key and by rank is not correct solution. The problem is that a change of one element affects ranks of many others. E.g., adding element 0 to the set s above change the ranks of all existing elements: s' = {0, 1, 3, 4, 6, 9}. rank(1) = 2, rank(4) = 4, rank(9) = 6.
Thanks.