Just a runnable solution
Code\n\nimpl Solution {\n    pub fn closest_room(rooms: Vec<Vec<i32>>, queries: Vec<Vec<i32>>) -> Vec<i32> {\n        use std::collections::BTreeSet;\n        f
# Code\n```\nimpl Solution {\n    pub fn closest_room(rooms: Vec<Vec<i32>>, queries: Vec<Vec<i32>>) -> Vec<i32> {\n        use std::collections::BTreeSet;\n        fn search_closest_room_id(tree_set: &BTreeSet<i32>, preferred_id: i32) -> i32 {\n            let floor = tree_set.range(..=preferred_id).next_back();\n            let ceiling = tree_set.range(preferred_id..).next();\n            let mut ans_abs = i32::MAX;\n            let mut ans = -1;\n            if let Some(&floor) = floor {\n                ans = floor;\n                ans_abs = (preferred_id - floor).abs();\n            }\n            if let Some(&ceiling) = ceiling {\n                if ans_abs > (preferred_id - ceiling).abs() {\n                    ans = ceiling;\n                }\n            }\n            ans\n        }\n        let mut rooms = rooms;\n        rooms.sort_by(|a, b| b[1].cmp(&a[1]));\n        let mut indexes = (0..queries.len()).collect::<Vec<_>>();\n        indexes.sort_by(|a, b| queries[*b][1].cmp(&queries[*a][1]));\n        let mut room_ids_so_far = BTreeSet::new();\n        let mut ans = vec![-1; queries.len()];\n        let mut i = 0;\n        for index in indexes {\n            while i < rooms.len() && rooms[i][1] >= queries[index][1] {\n                room_ids_so_far.insert(rooms[i][0]);\n                i += 1;\n            }\n            ans[index] = search_closest_room_id(&room_ids_so_far, queries[index][0]);\n        }\n        ans\n    }\n}\n```
['Rust']