Python solution with logarithmic complexity 
Intuition
Binary search to find interval ranges to update, which incurs log(n) complexity.
Approach
Use SortedDict so we can quickly find intervals that overlap
# Intuition\n* Binary search to find interval ranges to update, which incurs log(n) complexity. \n\n# Approach\n* Use SortedDict so we can quickly find intervals that overlap with [start, end] with binary search\n* Use SortedDict.irange() to iterate through the intervals to be merged. irange() is important to ensure linear time complexity.\n* Update the total along with the interval dictionary. \n\n# Complexity\n- Time complexity:\nAdd: o(klog(n)) where k is averange number of intervals to be merged.\ncount: o(1)\n\n- Space complexity:\no(n)\n\n# Code\n```python []\nfrom sortedcontainers import SortedDict\n\nclass CountIntervals(object):\n    def __init__(self):\n        self._dic = SortedDict()\n        self._total = 0\n\n    def add(self, left, right):\n        """\n        :type left: int\n        :type right: int\n        :rtype: None\n        """\n        start_ind = max(self._dic.bisect_right(left) - 1, 0)\n        end_ind = self._dic.bisect_right(right)\n        n = len(self._dic)\n\n        start_key = self._dic.iloc[start_ind] if start_ind < n else None\n        end_key = self._dic.iloc[end_ind] if end_ind < n else None\n\n        keys_to_remove = []\n        for k in self._dic.irange(start_key, end_key):\n            left1, right1 = k, self._dic[k]\n            if right < left1 or left > right1:\n                continue\n            \n            left = min(left, left1)\n            right = max(right, right1)\n            keys_to_remove.append(left1)\n        \n        # Remove smaller intervals\n        for k in keys_to_remove:\n            self._total -= (self._dic[k] - k + 1)\n            del self._dic[k]\n    \n        # Add covering intervals\n        self._dic[left] = right\n        self._total += (right - left + 1)\n \n    def count(self):\n        """\n        :rtype: int\n        """\n        return self._total\n        \n\n\n# Your CountIntervals object will be instantiated and called as such:\n# obj = CountIntervals()\n# obj.add(left,right)\n# param_2 = obj.count()\n```
['Python']