Suppose, there is an array of size N. Find number of elements are less than VAL. The array may contain duplicate values.
for example,
array = [ 1 , 2 , 3 , 1 , 2 ]
VAL = 3
So answer will be = 4.
Can it done by STL. (such as set/multiset ) in logarithmic time
I already googled it ,but failed to find solution with STL.
Thanks in advance.
I assume some preprocessing is allowed, otherwise it is not possible. After sorting each query can be answered in using std::lower_bound.
Thanks a lot, for your effort :)
But actually its a sub-problem which i trying to solve. To solve that problem i need online solution.
Any time update value and query is allowed. so preprocess will not work .
Easily done with ordered_set.
If the numbers are small enough, it can also be done using a binary indexed tree.. Otherwise you can compress all numbers (queries +array) and create a bit over it
Can be done in logn time using Fenwick tree or BIT. I assume that some preprocessing is allowed. As far as I know, femwick tree is not part of STL.
And I guess it can be done with Fenwick without preprocessing too!
Anyway the complexity will fall to O(log(N)*log(MAX_VAL)) if used map instead of array [or some other kind of complexity with hash/unordered map :) ]