The best way to solve this is to build an interval tree. (The range tree defined by sza is static. This means that after you create it, you cannot add / remove nodes. If this is normal with you, then its answer will be enough.)
Here you can find out about the interval tree:
Youtube: https://www.youtube.com/watch?v=q0QOYtSsTg4
Wiki: https://en.wikipedia.org/wiki/Interval_tree
The span tree is basically a binary tree based on the left value of the range tuple. ([left, right]). What is special is that each node in the tree has a value called max. The maximum value contains the largest right value of the nodes that are below this node, including the node itself. In other words, the current node will have a max value set to the largest right value of the subtree, which the current node is the root of.
To expand this for your problem, we can add a minimum value. If the min value will contain the smallest left value of the entire subtree, where this node is the root.
Edited screenshot from video: (sorry for the quality)

This means that when we request a number, you:
1) add current node to set of answers if number is inside range 2) go left if number is less than max value of left child. 3) go right if number is greater than min value of right child.
source share