C++ using sets and multisets | Beats 100% C++ Users
Intuition\nI found this problem very similar to https://cses.fi/problemset/task/1163\nand build my solution on top of the solution to this problem.\n\n# Code\n\
# Intuition\nI found this problem very similar to https://cses.fi/problemset/task/1163\nand build my solution on top of the solution to this problem.\n\n# Code\n```\nclass Solution {\npublic:\n    vector<bool> getResults(vector<vector<int>>& queries) {\n        set<int> positions;\n        multiset<pair<int,int>> lengths;\n        positions.insert(0);\n        positions.insert(1e9);\n        lengths.insert({1e9,1e9});\n        int n = queries.size();\n        vector<bool> ans;\n        for(int i=0;i<n;i++){\n            if (queries[i][0]==1) {\n                int p = queries[i][1];\n                positions.insert(p);\n                auto itr = positions.find(p);\n                int pre = *(prev(itr));\n                int nxt = *(next(itr));\n                auto itr1 = lengths.find({nxt-pre,nxt});\n                lengths.erase(itr1);\n                lengths.insert({p-pre,p});\n                lengths.insert({nxt-p,nxt});\n            } else {\n                int x = queries[i][1];\n                int sz = queries[i][2];\n                auto itr1 = lengths.lower_bound({sz,0});\n                bool check = false;\n                for (auto i = itr1; i!=lengths.end(); i = next(i)) {\n                    if ((*i).first >= sz) {\n                        if ((*i).second <=x) {\n                            check = true;\n                            break;\n                        } else {\n                            int prv = ((*i).second - (*i).first);\n                            int new_len1 = x -  prv;\n                            if (prv<x && new_len1 >= sz) {\n                                check = true;\n                                break;\n                            }\n                        }\n                        \n                    }\n                }       \n                ans.push_back(check);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']