Beats 100%
\n\n# Complexity\n- Time complexity: O(q log n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n + q)\n Add your space complexity here, e.
![image.png](https://assets.leetcode.com/users/images/6d7c52ca-a47a-4787-9ebd-aab8b3ff8798_1716807805.0450513.png)\n\n# Complexity\n- Time complexity: O(q log n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n + q)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass BIT:\n    def __init__(self, n):\n        self.n = n\n        self.l = [0] * (n + 1)\n    def add(self, i, x):\n        i += 1\n        while i <= self.n:\n            self.l[i] = max(x, self.l[i])\n            i += i & -i\n    def query(self, i):\n        i += 1\n        ans = 0\n        while i:\n            ans = max(ans, self.l[i])\n            i -= i & -i\n        return ans\n\nfrom sortedcontainers import SortedList\n    \nclass Solution:\n    def getResults(self, queries: List[List[int]]) -> List[bool]:\n        sl = SortedList()\n        n = min(5 * 10 ** 4, len(queries) * 3)\n        sl.add(0)\n        sl.add(n)\n        \n        ans = []\n        for q in queries:\n            if q[0] == 1:\n                x = q[1]\n                sl.add(x)\n        \n        bit = BIT(n + 1)\n        for x, y in pairwise(sl):\n            bit.add(y, y - x)\n        \n        for q in reversed(queries):\n            if q[0] == 1:\n                x = q[1]\n                index = sl.index(x)\n                after = sl[index + 1]\n                before = sl[index - 1]\n                sl.remove(x)\n                bit.add(after, after - before)\n            else:\n                _, x, sz = q\n                index = sl.bisect_right(x)\n                before = sl[index - 1]\n                ans.append(bit.query(before) >= sz or (x - before) >= sz)\n            \n        ans.reverse()\n        return ans\n        \n                \n        \n        \n```
['Python3']