Accesing multiset by indexing

Revision en1, by codeofthrone, 2020-04-14 10:07:30

In each query, I have to insert x in a vector so that it remains sorted and output the Yth element. Inserting was taking O(n) time.

I switched to multiset as it remains sorted on each insertion with O(log(n)) time but I am stuck in finding the Yth element. The only approach worked was to traverse the multiset from starting but again it gives TLE.

I searched the internet but couldn't found anything relevant. Is there any way to access the ith indexed element in multiset in O(log(n) ) time.

Consider I am using C++.

Thanks in advance.

Tags c++ 14, #multiset

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English codeofthrone 2020-04-14 10:07:30 582 Initial revision (published)