Block Placement Queries - PYTHON3 SOL.
Class Definition and Method Signature\n\nclass Solution:    \n    def getResults(self, queries: List[List[int]]) -> List[bool]:\n\nclass Solution:: Defines a cl
**Class Definition and Method Signature**\n```\nclass Solution:    \n    def getResults(self, queries: List[List[int]]) -> List[bool]:\n```\nclass Solution:: Defines a class named Solution.\ndef getResults(self, queries: List[List[int]]) -> List[bool]:: Defines a method getResults within the Solution class. This method takes queries, which is a list of lists containing integers, and returns a list of boolean values.\n\n**Initial Setup**\n```\nbit, res = [0] * (min(50000, 3 * len(queries)) + 1), []\n```\nbit: Initializes a list bit with zeros. The length of this list is either 50000 or three times the length of queries, whichever is smaller, plus one.\nres: Initializes an empty list res which will store the results.\n\n**Helper Function: bit_range**\n\n```\ndef bit_range(p, down=True):\n    while p >= 0 and p < len(bit):\n        yield p\n        p = (p & (p + 1)) - 1 if down else p | (p + 1)\n```\nbit_range(p, down=True): A generator function that yields indices based on the value of p and the down flag.\nIf down is True, it yields indices by decrementing p.\nIf down is False, it yields indices by incrementing p.\n\n**Helper Function: get_max**\n\n```\ndef get_max(p: int) -> int:\n    return max(bit[i] for i in bit_range(p))\n```\nget_max(p: int) -> int: This function returns the maximum value in the bit array within the range generated by bit_range(p).\n\n**Helper Function: update**\n\n```\ndef update(p, val):\n    for idx in bit_range(p, False):\n         bit[idx] = max(bit[idx], val)\n```\nupdate(p, val): This function updates the bit array. It sets each element in the range generated by bit_range(p, False) to the maximum of its current value and val.\n\n**Main Logic**\n```\nblocks = [0] + sorted([x for t, x, *sz in queries if t == 1])\nfor i, b in enumerate(blocks[1:]):\n    update(b, b - blocks[i])\n```\n\nblocks: Creates a list of unique x values from the queries where t == 1, and adds 0 at the start.\nLoop: For each element b in blocks (excluding the first element):\nCalls update(b, b - blocks[i]) to update the bit array.\n\n**Processing Queries**\n```\nfor t, x, *sz in reversed(queries):\n    p = bisect_left(blocks, x)\n    if t == 1:\n        if p + 1 < len(blocks):\n            update(blocks[p + 1], blocks[p + 1] - blocks[p - 1])\n        del blocks[p]\n    else:\n        res.append(x - blocks[p - 1] >= sz[0] or get_max(x) >= sz[0])\n```\nLoop: Iterates over the queries in reverse order.\np = bisect_left(blocks, x): Finds the position p where x should be inserted to keep blocks sorted.\nIf t == 1:\nIf p + 1 is within the bounds of blocks, calls update to update blocks[p + 1].\nRemoves blocks[p].\nIf t != 1:\nAppends a boolean value to res. The boolean value is True if the condition x - blocks[p - 1] >= sz[0] or get_max(x) >= sz[0] is met.\n\n**Return Results**\n\n```\nreturn reversed(res)\n```\nreturn reversed(res): Returns the results list in reversed order.\n\n\n**Full Code**\n```\nclass Solution:    \n    def getResults(self, queries: List[List[int]]) -> List[bool]:\n        bit, res = [0] * (min(50000, 3 * len(queries)) + 1), []\n        \n        def bit_range(p, down=True):\n            while p >= 0 and p < len(bit):\n                yield p\n                p = (p & (p + 1)) - 1 if down else p | (p + 1)\n        \n        def get_max(p: int) -> int:\n            return max(bit[i] for i in bit_range(p))\n        \n        def update(p, val):\n            for idx in bit_range(p, False):\n                bit[idx] = max(bit[idx], val)\n        \n        blocks = [0] + sorted([x for t, x, *sz in queries if t == 1])\n        for i, b in enumerate(blocks[1:]):\n            update(b, b - blocks[i])\n        \n        for t, x, *sz in reversed(queries):\n            p = bisect_left(blocks, x)\n            if t == 1:\n                if p + 1 < len(blocks):\n                    update(blocks[p + 1], blocks[p + 1] - blocks[p - 1])\n                del blocks[p]\n            else:\n                res.append(x - blocks[p - 1] >= sz[0] or get_max(x) >= sz[0])\n        \n        return reversed(res)\n```
['Python3']