sort query points and intermediate endpoints more and more often, in one array; for each point, keep a flag indicating whether this is an interval start, interval end, or request.
Initialize the counter to zero and view the list. Start increases the counter; the end reduces it; the query knows the number of overlapping intervals by reading the counter.
Time (N + M) .Log (N + M) or better if special sorting can be used.
If you are not allowed to sort the query points, just sort the endpoints of the interval. In one linear scan, you can calculate the number of overlaps immediately after each endpoint.
For a given query point, you will find the corresponding endpoint by a dichotomous search, therefore, the number of matches.
M.Log (M) + N.Log (M) for M intervals and N query points.
If you are not allowed to sort the intervals, just sort the query points.
Process each interval in turn, find the first query point on which it is superimposed, by dichotomous search and increase the counter of all query points that it overlaps.
N.Log (N) + M.Log (N) + O, where O is the total number of interval / query overlaps.
If you are not allowed to sort at all, carefully check each request for each interval, NM
source share