Binary search works on value ranges, not just array indices.
Counting how many elements satisfy a condition lets you use binary search to find thresholds.
Logarithmic time doesn't always mean logarithmic input size. Here, the logarithm comes from the range of values, not the number of elements.