✅Segment Trees || python
\n# Code\n\nclass TreeNode:\n    def __init__(self,l,r):\n        self.left=None\n        self.right=None\n        self.cnt=0\n        self.leftRange=l\n       
\n# Code\n```\nclass TreeNode:\n    def __init__(self,l,r):\n        self.left=None\n        self.right=None\n        self.cnt=0\n        self.leftRange=l\n        self.rightRange=r\n    \n    def insert(self,root,l,r):\n        if(root.leftRange>r or root.rightRange<l):return \n        if(root.leftRange<l or root.rightRange>r):\n            if(root.left==None):\n                root.left=TreeNode(root.leftRange,(root.leftRange+root.rightRange)//2)\n            if(root.right==None):\n                root.right=TreeNode((root.leftRange+root.rightRange)//2+1,root.rightRange)\n            self.insert(root.left,max(l,root.leftRange),min(r,(root.leftRange+root.rightRange)//2))\n            self.insert(root.right,max(l,(root.leftRange+root.rightRange)//2+1),min(r,root.rightRange))\n        else:\n            root.cnt=r-l+1\n        \n        cnt=0\n        if(root.left!=None):\n            cnt+=root.left.cnt\n        if(root.right!=None):\n            cnt+=root.right.cnt\n        root.cnt=max(root.cnt,cnt)\n\nclass CountIntervals:\n\n    def __init__(self):\n        self.root=TreeNode(0,1000000000)\n\n    def add(self, left: int, right: int) -> None:\n        self.root.insert(self.root,left,right)\n\n    def count(self) -> int:\n        return self.root.cnt\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```
['Design', 'Segment Tree', 'Python3']