C++, Map easy logic
class CountIntervals {\npublic:\n    mapmp;\n    int ans;\n    \n    CountIntervals() \n    {\n        mp.clear();\n        ans=0;\n    }\n    \n    void add(in
class CountIntervals {\npublic:\n    map<int,int>mp;\n    int ans;\n    \n    CountIntervals() \n    {\n        mp.clear();\n        ans=0;\n    }\n    \n    void add(int left, int right) \n    {\n        // main idea is to find less than or equal staring point in map which has ending proint greater than or equal to l (current interval) and merge it\n        \n        int l=left,r=right,cnt=0;\n        bool ok=true;\n        \n        if(mp.size()==0)\n        {\n            mp[left]=right;\n            ans+=r-l+1;\n            return;\n        }\n        \n        // idea is l.....r hai so r se chhota ya barabar starting point dhoonhdo jiska ending point >=l ho aur usko merge krdo\n        // think and u will get it, small milate jaao large banate jaao \n        \n        while(ok)\n        {\n            auto itl=mp.upper_bound(r);\n    \n            ok=false;\n            \n            if(itl!=mp.begin())\n            {\n                itl--;\n            }\n            \n            if(itl!=mp.end() && itl->first<=r && itl->second>=l)\n            {\n                ok=true;\n                ans=ans-(itl->second-itl->first+1);\n                l=min(l,itl->first);\n                r=max(r,itl->second);\n                mp.erase(itl);\n            }\n        }\n        \n        \n        mp[l]=r;\n        ans+=r-l+1;\n    }\n    \n    int count() \n    {\n       return ans; \n    }\n};\n\n/**\n * Your CountIntervals object will be instantiated and called as such:\n * CountIntervals* obj = new CountIntervals();\n * obj->add(left,right);\n * int param_2 = obj->count();\n */
['C', 'Binary Tree']