C++, binary search
\n//TC: O(nlogn + 2 * mlogm + nlogm)\nvector<int> closestRoom(vector<vector<int>>& room, vector<vector<int>>& query) {\n        int n = query.size();\n        v
```\n//TC: O(nlogn + 2 * mlogm + nlogm)\nvector<int> closestRoom(vector<vector<int>>& room, vector<vector<int>>& query) {\n        int n = query.size();\n        vector<vector<int>> tquery;\n        for(int i = 0; i < n; i++) tquery.push_back({query[i][0], query[i][1], i});\n        auto cmp = [](const auto& a, const auto& b){return a[1] > b[1];};\n        sort(begin(room), end(room), cmp);  //O(mlogm)\n        sort(begin(tquery), end(tquery), cmp);  //O(nlogn)\n        vector<int>res(n);\n        int j = 0;\n        int m = room.size();\n        set<int> ts;\n\t\t////O(mlogm + nlogm)\n        for(int i = 0; i < n; i++){\n            while(j < m && room[j][1] >= tquery[i][1]) ts.insert(room[j++][0]);\n            if(ts.empty()) res[tquery[i][2]] = -1;\n            else{\n                auto it = ts.lower_bound(tquery[i][0]);\n                if(it != begin(ts)){\n                    auto bit = it;\n                    it--;\n                    res[tquery[i][2]] = abs(*bit - tquery[i][0]) < abs(*it - tquery[i][0]) ? *bit : *it;\n                }\n                else res[tquery[i][2]] = *it;\n            }\n        }\n        return res;\n\n    }\n```
[]