Single Ordered Map based solution with 516ms 91.12% fast
We use ordered map to store all intervals as there right as keys and left as values then whenever a new interval comes we test if we have any itersecting interv
We use ordered map to store all intervals as there right as keys and left as values then whenever a new interval comes we test if we have any itersecting interval or not if no intersection is found the insert it directly and update the count(cnt) as right-left+1,else if itersection is found then we need to modify the boundaries and then again re-insert the new interval recursively.\n\n\nTo find the interval that might intersect with this we can use lower_bound() to find the next ending after the current starting point.\n\n**C++:**\n\'\'\'\n\n    class CountIntervals {\n    public:\n        CountIntervals() {\n\n        }\n    \n    void add(int left, int right) {\n       \n        //find the interval which is equal or just next right as the current interval e.g [2,5] with [5,6]\n        //because it may have intersection with the current one\n        auto it = hm.lower_bound(left);\n        \n        //if not interval is found just add this and increment integer count\n        if(it == hm.end()){\n            hm[right] = left;\n            cnt+=(right-left+1);\n        }\n        \n        //if next interval fount\n        else{\n            \n            //take the start and end value of the suspected interval\n            int s = it->second;\n            int e = it->first;\n            \n            \n            //no intersection is fount as the interval which is found comes after the current interval\n            if(s > right){\n                hm[right] = left;\n                cnt+=(right-left+1);\n            }\n            \n            //if intersection fount erase that interval as we need to modify its boundaries\n        //remove its contribution from cnt and the find new boundary as min(start,left) and max(end,right)\n            \n            else{\n                hm.erase(e);\n                cnt -= (e-s+1);\n                int ns = min(left,s),ne = max(right,e);\n                //add the new interval to the map reccursively.\n                add(ns,ne);\n            }\n        }\n    }\n    \n    int count() {\n        return cnt;\n    }\n    \n    private:\n        map<int,int> hm;\n        int cnt = 0;\n    };\n\n\n\'\'\'
['Tree', 'Binary Tree']