javascript treeset 444ms 100%
reference:\nhttps://github.com/python/cpython/blob/3.9/Lib/bisect.py\nhttps://github.com/fukatani/TreeSet/blob/master/treeset.py\n\nJava Version:\nhttps://leetc
reference:\nhttps://github.com/python/cpython/blob/3.9/Lib/bisect.py\nhttps://github.com/fukatani/TreeSet/blob/master/treeset.py\n\nJava Version:\nhttps://leetcode.com/problems/closest-room/discuss/1186546/java-TreeSet-81ms\n```\nfunction Bisect() {\n    return { insort_right, insort_left, bisect_left, bisect_right }\n    function insort_right(a, x, lo = 0, hi = null) {\n        lo = bisect_right(a, x, lo, hi);\n        a.splice(lo, 0, x);\n    }\n    function bisect_right(a, x, lo = 0, hi = null) {\n        if (lo < 0) throw new Error(\'lo must be non-negative\');\n        if (hi == null) hi = a.length;\n        while (lo < hi) {\n            let mid = lo + hi >> 1;\n            x < a[mid] ? hi = mid : lo = mid + 1;\n        }\n        return lo;\n    }\n    function insort_left(a, x, lo = 0, hi = null) {\n        lo = bisect_left(a, x, lo, hi);\n        a.splice(lo, 0, x);\n    }\n    function bisect_left(a, x, lo = 0, hi = null) {\n        if (lo < 0) throw new Error(\'lo must be non-negative\');\n        if (hi == null) hi = a.length;\n        while (lo < hi) {\n            let mid = lo + hi >> 1;\n            a[mid] < x ? lo = mid + 1 : hi = mid;\n        }\n        return lo;\n    }\n}\n\nfunction TreeSet(elements) {\n    let ts = [];\n    let se = new Set();\n    let bisect = new Bisect();\n    if (elements) addAll(elements);\n    return { add, floor, ceiling, remove, contains, size, clear, toArray };\n    function addAll(elements) {\n        for (const e of elements) {\n            if (se.has(e)) continue;\n            add(e);\n            se.add(e);\n        }\n    }\n    function add(e) {\n        if (!se.has(e)) {\n            bisect.insort_right(ts, e);\n            se.add(e);\n        }\n    }\n    function ceiling(e) {\n        let idx = bisect.bisect_right(ts, e);\n        if (ts[idx - 1] == e) return e;\n        return ts[bisect.bisect_right(ts, e)];\n    }\n    function floor(e) {\n        let idx = bisect.bisect_left(ts, e);\n        if (ts[idx] == e) {\n            return e;\n        } else {\n            return ts[bisect.bisect_left(ts, e) - 1];\n        }\n    }\n    function remove(e) {\n        ts = ts.filter(x => x != e);\n        se.delete(e);\n    }\n    function contains(e) {\n        return se.has(e);\n    }\n    function size() {\n        return ts.length;\n    }\n    function clear() {\n        ts = [];\n    }\n    function toArray() {\n        return ts;\n    }\n}\n\nconst closestRoom = (rooms, queries) => {\n    rooms.sort((x, y) => y[1] - x[1]);\n    let qn = queries.length;\n    queries = queries.map((t, i) => [i, ...t]);\n    queries.sort((x, y) => y[2] - x[2]);\n    let res = Array(qn).fill(0);\n    let ri = 0;\n    let ts = new TreeSet();\n    for (const e of queries) {\n        let qi = e[0];\n        let qid = e[1];\n        let qmize = e[2];\n        while (ri < rooms.length && rooms[ri][1] >= qmize) {\n            ts.add(rooms[ri][0]);\n            ri++;\n        }\n        if (ts.size() == 0) {\n            res[qi] = -1;\n        } else {\n            let lower = ts.floor(qid) || -1000000000;\n            let higher = ts.ceiling(qid) || 1000000000;\n            if (qid - lower <= higher - qid) {\n                res[qi] = lower;\n            } else {\n                res[qi] = higher;\n            }\n        }\n    }\n    return res;\n};\n```
['Tree', 'Binary Tree', 'Ordered Set', 'JavaScript']