This is not a complete solution, just an idea. How about creating a quadtree on axes A and B? You would go down a tree, say, wide; then:
- whenever you find a subtree with A values outside the specified range [X, Y], you drop that subtree (and do not recurse);
- every time you find a subtree with A-values within the given range [X, Y], you add this subtree to the set S, which you build and do not return;
- whenever you find a subtree with some A values inside the range [X, Y] and some external ones, you recurs into it.
Now you have a set S of all maximal subtrees with A-coordinates between X and Y; i.e. no more than O (sqrt (m)) of these subtrees, which I will show below.
Some of these subtrees will contain O (m) entries (of course, they will contain O (m) entries that are all added together), so we can’t do anything for all entries of all subtrees. Now we can make a bunch of subtrees in S, so the B-minimum of each subtree is less than the B-minimums of its children in the heap. Now extract the B-minimal elements from the top of the node heap until you have N of them; whenever you retrieve an element from a subtree with elements k, you need to decompose this subtree into O (log (k)) subtrees that do not contain the newly selected element.
Now consider the complexity. Finding subtrees O (sqrt (m)) will take no more than step O (sqrt (m)) (an exercise for the reader, using the arguments in the proof below). We should probably put them in a bunch when we find them; it takes a step O (sqrt (m) * log (sqrt (m))) = O (sqrt (m) * log (m)). Extracting one element from the subtree of k-elements in the heap takes O (sqrt (k)) time to find the element, and then insert the O (log (sqrt (k))) = O (log (k)) submenu into a heap of size O (sqrt (m)) takes O (log (k) * log (sqrt (m))) = O (log (k) * log (m)). We can probably be smarter using potentials, but we can at least bind k to m, so leave N * (O (sqrt (k) + log (k) * log (m))) = O ( N * (sqrt (m) + log (m) ^ 2) = O (N * sqrt (m)) for extraction, and O (sqrt (m) * (N + log (m))) steps in total ... that sublinear in m.
Here is the proof of the estimate of the subsets O (sqrt (m)). There are several strategies for constructing a quadrant, but for the convenience of analysis, suppose we create a binary tree; in the root of the node, we break the data set by the A-coordinate around the point with the median A-coordinate, then one level down we break the data set by the B-coordinate around the point with the middle B-coordinate (which is the median for half the points contained in this half-element ) and continue alternating directions to the level.
The height of the tree is log (m). Now consider how many subtrees we need to recurse. We only need to rewrite if the subtree contains the A-coordinate of X or contains the A-coordinate of Y or both. At the (2 * k) -th level down there are only 2 ^ (2 * k) subtrees. By that time, each subtree has its own A-range divided by k times already, and each time we do this, only half of the trees contain the A-coordinate X. Therefore, no more than 2 ^ k subtrees contain the A-coordinate X. Similarly, at most 2 ^ k will contain the A-coordinate Y. This means that in total we recurse no more than 2 * sum (2 ^ k, k = 0. log (m) / 2) = 2 * (2 ^ (log (m) / 2 - 1) + 1) = O (sqrt (m)).
Since we explore no more than 2 ^ k subtrees at the (2 * k) 'level down, we can also add no more than 2 ^ k subtrees at this level in S. This gives the final result.