Python segment tree
\nclass Node:\n    def __init__(self, start, end, val=0):\n        self.start = start\n        self.end = end\n        self.val = val\n        self.left = self.
```\nclass Node:\n    def __init__(self, start, end, val=0):\n        self.start = start\n        self.end = end\n        self.val = val\n        self.left = self.right = None\n        \nclass CountIntervals:\n\n    def __init__(self):\n        self.root = Node(1, 10**9)\n\n    def add(self, start: int, end: int) -> None:\n        self.update(self.root, start, end)\n    \n    def update(self, node, start, end):\n#         to avoid updating what we already have with a lesser value...\n        if node.val == node.end-node.start+1:\n            return\n        \n        if node.start == start and node.end == end:\n            node.val = node.end - node.start +1\n            return\n        \n        mid = (node.start + node.end) // 2\n        \n        if not node.left:\n            node.left = Node(node.start, mid, 0)\n        if not node.right:\n            node.right = Node(mid+1, node.end, 0)\n        \n        if end <= mid:\n            self.update(node.left, start, end)\n        elif start >= mid + 1:\n            self.update(node.right, start, end)\n        else:\n            self.update(node.left, start, mid)\n            self.update(node.right, mid+1, end)\n            \n        node.val = node.left.val + node.right.val \n        return\n\n    def count(self) -> int:\n        return self.root.val\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```
[]