using set and sorting algorithm
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                vector<pair<int,int>>store,first;\n                for(int i=0;i<r.size();i++){\n                    store.push_back({r[i][1],r[i][0]});\n\n                }\n\n                for(int i=0;i<q.size();i++){\n                    first.push_back({q[i][1],i});\n                }\n                int n1=q.size();\n                vector<int>ans(n1,-1);\n\n                sort(store.begin(),store.end());\n                sort(first.begin(),first.end());\n                int j=store.size()-1;\n                set<int>st;\n                for(int i=q.size()-1;i>=0;i--){\n                    int val=first[i].first;\n                    int index=first[i].second;\n                    int id=q[index][0];\n                    pair<int,int>p={val,0};\n                    int l=lower_bound(store.begin(),store.end(),p)-store.begin();\n                    cout<<index<<" "<<id<<" "<<l<<"  ";\n                    while(j>=l){\n                        st.insert(store[j].second);\n                        j-=1;\n                    }\n                    if(st.size()==0){\n                        continue;\n                    }\n\n                    auto it=st.lower_bound(id);\n                    if(it==st.end()){\n                        it--;\n                        ans[index]=*it;\n                    }\n\n                    else if(it==st.begin()){\n                        ans[index]=*it;\n                    }\n                    else{\n                        int f=*it;\n                        it--;\n                        int s=*it;\n                        if(abs(s-id)<=(f-id)){\n                            ans[index]=s;\n                        }\n                        else ans[index]=f;\n                    }\n\n\n                }\n\n\n\n\n\n                          return ans;\n\n\n        \n    }\n};\n```
['C++']