Day 254 Problem 2 Solved
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# Code\n\nfrom sorted
# 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# Code\n```\nfrom sortedcontainers import SortedList\n\n\nclass Solution:\n    def getResults(self, queries: List[List[int]]) -> List[bool]:\n        barriers = SortedList()\n        barriers.add(0)\n        for query in queries:\n            if query[0] == 1:\n                it = query[1]\n                barriers.add(it)\n        holes = SortedList()\n        holes.add(float("inf"))\n        hole2start = {float("inf"): barriers[-1]}\n        for pos in range(len(barriers) - 1):\n            start = barriers[pos]\n            end = barriers[pos + 1]\n            size = end - start\n            if size:\n                pos = holes.bisect_left(size)\n                hole_size = holes[pos]\n                if hole2start[hole_size] > start:\n                    if hole_size > size:\n                        holes.add(size)\n                    hole2start[size] = start\n        barriers.add(float("inf"))\n        result = []\n        for query in reversed(queries):\n            if query[0] == 1:\n                it = query[1]\n                pos = barriers.bisect_left(it)\n                left = barriers[pos - 1]\n                right = barriers[pos + 1]\n                size = right - left\n                hole_pos = holes.bisect_left(size)\n                if hole2start[holes[hole_pos]] > left:\n                    while hole_pos > 0 and hole2start[holes[hole_pos - 1]] > left:\n                        del hole2start[holes[hole_pos - 1]]\n                        del holes[hole_pos - 1]\n                        hole_pos -= 1\n                    hole2start[size] = left\n                    if holes[hole_pos] != size:\n                        holes.add(size)\n                barriers.remove(it)\n            else:\n                _, start, size = query\n                hole_pos = holes.bisect_left(size)\n                hole = holes[hole_pos]\n                result.append(hole2start[hole] <= start - size)\n        result.reverse()\n        return result\n\n```
['Python3']