In the end, it's pretty hard to think about these issues. What you actually have is a one-dimensional space acting on a line. By adding depth, you get the second coordinate. By requesting a unique depth, you can actually draw a picture.
Your request should cross each interval (line) of your image with a rectangle from x1 to x2 and every y in Y.
So a naive view of this problem is to compare each line in y order if it intersects. Since you need all the results, it takes O (n) to find the answer. And this answer should also be sorted by depth in O (m log m).
You are trying to go with a one-dimensional R-tree. Allows you to define areas on the go. Within such a structure, each node spans a region from min to max. Now you can divide this region further. Since there are gaps in both sections, since the separation actually separates it, they are stored in the node (and not in the child nodes). Within these child nodes, you again get such a list, and so on.
To search, you check all nodes and child nodes whose regions intersect with the search interval.
In each node, the list of intervals is sorted by their depth values.
Thus, the problem boils down to a series of sorted lists (of all the intervalls that may be contained within your search interval). These lists should now be filtered for each interval that really crosses your search interval. But you do not need to filter everything. Since if such a node interval is completely contained within your search interval, all its intervals and all its child intervals really intersect with the search interval (since they are completely contained inside).
To combine all of these lists, you simply use a combination of compounds in which you select the next element of this association, which has the smallest depth. You sort all of these lists by the depth of your first item (the item with the smallest depth in each list). Now you are looking for the first element and move it to the result. Now you compare the next item in the list with the first item in the next list, and if the depth is even less, you copy it. If the depth becomes greater, you simply sort it with the correct position, taking log k (where k is the number of non-empty lists in your collection) and continue with the first list and repeat it until all the lists are empty or go through work since You keep the cursor position for each list.
This way you only sort the lists and compare them with the next element if it is even smaller or inserts it.
This is the best structure that I can think of. at first you easily exclude almost all intercepts that cannot intersect with it. How do you compose a result based on lists of potentials in which you have lists that, as you know, are part of the result in full (it can be argued that you need to check only a certain number of jump lists, since the trees diverge very quickly). By controlling the separation strategy, you control the value of each piece. If, for example, you split only at> 10 intervals, you will provide k
In the worst case, this is bad, but I assume that the expected actual performance will be good and better than O (n + m log m), since you are already using various sorted lists of potential intersections.
And remember that if a node has children, it itself contains a list of all the intervals that intersect with the split point. Therefore, if your search interval also intersects with the split point, each interval of this node is also part of your result.
Therefore, feel free to experiment with this structure. This should be easy to implement in one day.