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.