[Python3] built-in List beats SortedList
Idea\n1. Initialize list interv with  [(-inf, -inf), (inf, inf)] to store the merged intervals and integer cov = 0, to be updated after addition of each interva
### Idea\n1. Initialize list `interv` with  `[(-inf, -inf), (inf, inf)]` to store the merged intervals and integer `cov = 0`, to be updated after addition of each interval\n2. Whenever an interval must be added, the following must be done\n- Using binary search, find the range of affected intervals in `interv`, denoted by `li` for left most, `ri` for right most + 1\n- the range of the new merged interval (`lval`, `rval`)\n- replace the range of [li, ri - 1], inclusive with the new merged interval `(lval, rval)`\n3. Update the coverege by\n- Finding and subtracting the coverage of deleted intervals `to_delete`\n- Adding the coverage of new interval `rval - lval + 1`\n\n### Code\n#### Built-in List\n```\nclass CountIntervals:\n\n    def __init__(self):\n\t# initialize the merged intervals list as below to handle edge cases\n        self.interv = [(-inf, -inf), (inf, inf)]\n        self.cov = 0   \n\n    def add(self, left: int, right: int) -> None:\n        \n        interv = self.interv\n        \n\t\t# find the left most position for inserting of the new potentially merged interval\n\t\t# we use `left - 1` because the interval coverage is inclusive\n        li = bisect.bisect_left(interv, left - 1, key=itemgetter(1))\n        lval = min(interv[li][0], left)\n\t\t\n\t\t# find the right most position for inserting the new potentially merged interval\n\t\t# we use `right + 1` because the interval coverage is inclusive\n        ri = bisect.bisect_right(interv, right + 1, key=itemgetter(0))\n        rval = max(interv[ri - 1][1], right)\n\n\t\t# find the coverage of the intervals that will be replaced by the new interval\n        to_delete = 0\n        for _ in range(li, ri):\n            to_delete += interv[_][1] - interv[_][0] + 1\n            \n\t\t# udpate the coverage\n        self.cov += rval - lval + 1 - to_delete\n        interv[li: ri] = [(lval, rval)]\n\n    def count(self) -> int:\n        return self.cov\n```\n\n#### SortedList\n```\nfrom sortedcontainers import SortedList\n\nclass CountIntervals:\n\n    def __init__(self):\n        self.cov = 0 \n        self.interv = SortedList([(-inf, -inf), (inf, inf)])\n\n    def add(self, left: int, right: int) -> None:\n        li = self.interv.bisect_left((left - 1, -inf))\n        if self.interv[li - 1][1] >= left - 1:\n            li -= 1\n        lval = min(self.interv[li][0], left)\n        ri = self.interv.bisect_right((right + 1, inf))\n        rval = max(self.interv[ri - 1][1], right)\n        \n        \n        to_delete = 0\n        for _ in range(li, ri):\n            to_delete += self.interv[_][1] - self.interv[_][0] + 1\n        self.cov += rval - lval + 1 - to_delete\n        del self.interv[li: ri]\n        self.interv.add((lval, rval))\n\n    def count(self) -> int:\n        return self.cov\n```\n\n### Feedback\nI appreciate your feedback and support! :)
['Binary Tree', 'Python', 'Python3']