Lets say we have a running stream of numbers. We have to insert each element to a sorted list, before inserting we have to find the position of element in list. The only way I know to do it efficiently is augmenting a AVL tree. And also there are policy based data structures. do you know some algorithm that can do this in logn?
You can do it in $$$O(nlog n)$$$ by keeping a BIT that stores frequency of elements, if the elements are not too large.
Why it is $$$O(n\log^2n)$$$? Isn't it $$$O(n\log n)$$$?
We have one $$$O(logn)$$$ factor from binary search and one from fenwick tree.
How will you do it $$$O(nlogn)$$$ otherwise?
I think your binary search can be replaced by an unordered map for discretization to cut the log n
edit: typo
Sorry, but I don't believe in unordered_map :)
https://codeforces.com/blog/entry/21853
maybe
I think I misunderstood you. What the purpose of binary search?
Hmm. Okay, I miunderstood the problem. Can be done in O(nlogn).
I think there is a O(n logn) method which is to use an unordered map to discretize. (may have large constant factor)
Then we use a fenwick tree to see how many elements are placed in front of a certain index.
But that's assuming that you can preprocess your stream of numbers