Python (Simple Segment Tree)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Node:\n    def __init__(self):\n        self.val = 0\n        self.left = None\n        self.right = None\n\n    def add(self, node, x, y, s, e):\n        if x >= e or y <= s or node and node.val == y-x:\n            return node \n\n        if node is None:\n            node = Node()\n\n        if x >= s and y <= e:\n            node.val = y-x \n            return node \n\n        mid = (x+y)//2 \n\n        node.left = self.add(node.left,x,mid,s,e)\n        node.right = self.add(node.right,mid,y,s,e)\n\n        node.val = 0 \n\n        if node.left:\n            node.val += node.left.val \n\n        if node.right:\n            node.val += node.right.val\n\n        return node \n\nclass CountIntervals:\n    def __init__(self):\n        self.root = Node()\n\n    def add(self, left, right):\n        self.root.add(self.root,1,10**9+1,left,right+1)\n\n    def count(self):\n        return self.root.val\n```
['Python3']