C++ Segment Tree with explaination and comments
class FenwickTree{\n    public:\n    vectorbit;\n    int n;\n    FenwickTree(int n){\n        this->n=n;\n        bit= vector(n+1,0);\n    }\n    void add(int i
class FenwickTree{\n    public:\n    vector<int>bit;\n    int n;\n    FenwickTree(int n){\n        this->n=n;\n        bit= vector<int>(n+1,0);\n    }\n    void add(int id,int val){\n        while(id<=n){\n            bit[id]=max(bit[id],val);\n            id+=(id&-id);\n        }\n    }\n    int query(int id){\n        int maxAns=0;\n        while(id>0){\n            maxAns=max(maxAns,bit[id]);\n            id-=(id&-id);\n        }\n        return maxAns;\n    }\n};\nclass Solution {\npublic:\n    vector<bool> getResults(vector<vector<int>>& queries) {\n        set<int>obstaclePoints;\n        int n=min(5*10000,3*(int)queries.size())+1;\n        obstaclePoints.insert(0),obstaclePoints.insert(n);\n        FenwickTree ft(n);\n        for(auto q:queries){\n            int type=q[0];\n            if(type==1){\n                int x=q[1];\n                obstaclePoints.insert(x);\n            }\n        }\n            //iterate over all obstacles\n        for(auto it=obstaclePoints.begin();it!=obstaclePoints.end();++it){\n            if(it==obstaclePoints.begin())continue;\n            auto prevIt=prev(it);\n            int x=*it,gapSize=(*it-*prevIt);\n            ft.add(x,gapSize);\n        }\n        vector<bool>ans;\n        for(int i=queries.size()-1;i>=0;i--){\n            vector<int>&q=queries[i];\n            int type=q[0];\n            if(type==1){\n                int x=q[1];\n                auto it=obstaclePoints.find(x);\n                auto prv=prev(it);\n                auto nxt=next(it);\n                obstaclePoints.erase(it);\n                ft.add(*nxt,(*nxt-*prv));\n            }\n            else{\n                int x=q[1],sz=q[2];\n                auto nxt=obstaclePoints.upper_bound(x);\n                auto prv=prev(nxt);\n                int maxGap=max(ft.query(*prv),x-*prv);\n                ans.push_back(maxGap>=sz);\n            }\n        }\n        reverse(ans.begin(),ans.end());\n        return ans;\n\n    }\n   \n};
['C']