Offline Query processing binary search closest value
\nimport bisect\n\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        n = len(rooms)\n        q
```\nimport bisect\n\nclass Solution:\n    def closestRoom(self, rooms: List[List[int]], queries: List[List[int]]) -> List[int]:\n        n = len(rooms)\n        q = len(queries)\n        res = [-1] * q\n        queries = [[queries[i][0], queries[i][1], i] for i in range(q)]\n        queries.sort(key = lambda x: -x[1])\n        rooms.sort(key = lambda x: -x[1])\n        i = 0\n        ids = []\n        for p, s, pos in queries:\n            while i < n and rooms[i][1] >= s:\n                bisect.insort(ids, rooms[i][0])\n                i += 1\n            j = bisect.bisect_left(ids, p)\n            curr = (float(\'inf\'), -1)\n            for k in [j - 1, j, j + 1]:\n                if 0 <= k < len(ids):\n                    curr = min(curr, (abs(p - ids[k]), ids[k]))\n            res[pos] = curr[1]\n        return res\n```\n![image](https://assets.leetcode.com/users/images/e22f2d27-9234-4473-a3d1-6066c8554ced_1687915252.2200313.png)
['Python']