[Python] Segment Tree got TLE. Why?
I got TLE for using segment tree. Why is my solution so slow? I had to rewrite the solution with SortedList and interval-merge to make it pass during the contes
I got TLE for using segment tree. Why is my solution so slow? I had to rewrite the solution with SortedList and interval-merge to make it pass during the contest. It costs me another 20 minutes.\n\n```\nclass Node:\n    def __init__(self):\n        self.count = 0\n        self.left = self.right = None\n\n\nclass CountIntervals:\n\n    def __init__(self):\n        self.root = Node()\n\n\n    def add(self, left: int, right: int) -> None:\n        self._add(self.root, 1, 10**9, left, right)\n\n\n    def _add(self, node, l, r, left, right):\n        if not node:\n            node = Node()\n        if node.count == r-l+1:\n            return node\n        if l > right or r < left:\n            return node\n        if left <= l and r <= right:\n            node.count = r-l+1\n            # print(l, r, node.count)\n            return node\n        mid = (l+r) // 2\n        node.left = self._add(node.left, l, mid, left, right)\n        node.right = self._add(node.right, mid+1, r, left, right)\n        node.count = node.left.count + node.right.count\n        # print(l, r, node.count, node.left.count, node.right.count)\n        return node\n\n\n    def count(self) -> int:\n        return self.root.count\n```
['Tree', 'Python']