Python Hard
```python3 []
from sortedcontainers import SortedList

class CountIntervals:

    def __init__(self):
        self.sl = SortedList()
        self.total = 0


    def add(self, left: int, right: int) -> None:
        while True:
            index = self.sl.bisect_left((left, right))
            if index < len(self.sl) and self.sl[index][0] <= right:
                l, r = self.sl.pop(index)
                self.total -= r - l + 1
                left = min(left, l)
                right = max(right, r)

            elif 0 <= index - 1 and self.sl[index - 1][1] >= left:
                l, r = self.sl.pop(index - 1)
                self.total -= r - l + 1
                left = min(left, l)
                right = max(right, r)

            else:
                break

        self.sl.add((left, right))
        self.total += right - left + 1

        

    def count(self) -> int:
        return self.total
        


# Your CountIntervals object will be instantiated and called as such:
# obj = CountIntervals()
# obj.add(left,right)
# param_2 = obj.count()
```
['Python3']