[C++] Sort + Binary Search
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> closestRoom(vector<vector<int>>& R, vector<vector<int>>& Q) {\n        unordered_map<int, unordered_set<int>> sz_mp;\n        for(auto & r : R) sz_mp[r[1]].insert(r[0]);\n        vector<pair<int, unordered_set<int>>> sz;\n        for(auto& [s, rm] : sz_mp) sz.push_back({s, rm});\n        sort(begin(sz), end(sz), [](auto &a, auto & b) {return a.first > b.first;});\n\n        for(int i = 0; i < Q.size(); i++) Q[i].push_back(i);\n        sort(begin(Q), end(Q), [](auto &a, auto & b) {return a[1] > b[1];});\n\n        vector<int> res(Q.size(), -1);\n        set<int> seen;\n        for(int i = 0, j = 0; i < Q.size(); i++) {\n            auto & q = Q[i];\n            int id = -1, diff = INT_MAX;\n            while(j < sz.size() && sz[j].first >= q[1]) {\n                for(auto k : sz[j].second) seen.insert(k);\n                j++;\n            }\n\n            if(seen.size()) {\n                auto it = seen.upper_bound(q[0]);\n                int diff = it != seen.end() ? abs(*it-q[0]) : INT_MAX, ans = it != seen.end() ? *it : INT_MAX;\n                if(it != seen.begin()) {\n                    it = prev(it);\n                    int diff2 = abs(*it-q[0]);\n                    if(diff2 <= diff) ans = *it;\n                }\n                res[q[2]] = ans == INT_MAX ? -1 : ans;\n            }\n        }\n        return res;\n    }\n};\n```
['C++']