C++ Solution without Segment tree [Beat 100%]
 Describe your first thoughts on how to solve this problem.  \nFirst time sharing my solution, if you think this is helpful, please upvote!\n\n# Approach\n\nFir
<!-- Describe your first thoughts on how to solve this problem. -->\nFirst time sharing my solution, if you think this is helpful, please upvote!\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst, insert all obstacals then we start from the last query\n### if query = 1: merge two space\n1. Delete two space sepreated by obstacle, merge them then insert back to set\n2. Update previous obstacle of the next obstacle and the next obstacle of the previous obstacle.\n### if query = 2: check if there a space big enough\n1. Use lower_bound() to find the segment with enough space, then start check if there is one space can fit the requirement.\n\n# Arguments\nmp : int -> <int, int>, (each obstacle -> <previous obsacle, next obstacle>)\ns : set <int, int>,  ({space size, the start of the space})\nx: the current query\'s obstacle\nx_f: the previous obstacle of x\nx_l: the next obstacle of x\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<bool> getResults(vector<vector<int>>& queries) {\n        vector<bool> ans;\n        int q = queries.size();\n        vector<int> bar;\n        map<int, pair<int,int>> mp;\n        set<pair<int,int>> s;\n        set<pair<int,int>>::iterator it;\n\n        bar.push_back(0);\n        bar.push_back(50001);\n        for(int i=0; i<q; i++){\n            if(queries[i][0] == 1){\n                bar.push_back(queries[i][1]);\n            }\n        }\n        \n        sort(bar.begin(), bar.end());\n        int bar_sz = bar.size();\n\n        mp[bar[0]] = {bar[0], bar[1]};\n        for(int i=1; i<bar_sz-1; i++){\n            mp[bar[i]] = {bar[i-1], bar[i+1]};\n        }\n        mp[bar[bar_sz-1]] = {bar[bar_sz-2], 0};\n        \n        \n        for(int i=0; i<bar.size()-1; i++){\n            s.insert({bar[i+1]-bar[i], bar[i]});\n        }\n        s.insert({0,bar[bar_sz-1]});\n        \n\n        for(int i=q-1; i>=0; i--){\n            if(queries[i][0] == 1){\n                int x = queries[i][1];\n                int x_f = mp[x].first;\n                int x_l = mp[x].second;\n                \n                s.erase({x-x_f, x_f});\n                s.erase({x_l-x, x});\n                mp[x_f].second = x_l;\n                mp[x_l].first = x_f;\n                s.insert({x_l-x_f, x_f});\n            }\n            else{\n                int x = queries[i][1];\n                int y = queries[i][2];\n                if(y>x){\n                    ans.push_back(false);\n                    continue;\n                }\n                \n                it = s.lower_bound({y,0});\n                bool can = false;\n                for (it; it!=s.end(); it++){\n                    if(y + it->second <= x){       \n                        can = true;\n                        break;\n                    }\n                }     \n                ans.push_back(can);         \n            }\n        }\n         \n        reverse(ans.begin(), ans.end());\n        return ans;\n    }\n};\n```
['C++']