https://codeforces.com/blog/entry/11080 + Comments.

Can be used for kth order statistics on multiset. Technique discussed in comments. But only pitfall is: Can MLE. Use Fenwick Tree + Binary Search instead.