c++ set with lambda logN seat logN leave time
\ntypedef set<pair<int,int>, function<bool(const pair<int, int>&, const pair<int, int>&)>> customSet;\nclass ExamRoom {\nprivate:\n    int N;\n    customSet pq;
```\ntypedef set<pair<int,int>, function<bool(const pair<int, int>&, const pair<int, int>&)>> customSet;\nclass ExamRoom {\nprivate:\n    int N;\n    customSet pq;\n    unordered_map<int, pair<customSet::iterator, customSet::iterator>> indexes;\npublic:\n    ExamRoom(int N) {\n        this->N = N;\n        auto comp = [N] (const pair<int, int>& a, const pair<int, int>& b) {\n            int res1 = (a.first == -1) ? a.second : (a.second == N) ? (a.second - a.first - 1) : ((a.second - a.first) / 2);\n            int res2 = (b.first == -1) ? b.second : (b.second == N) ? (b.second - b.first - 1) : ((b.second - b.first) / 2);\n            if (res1 != res2)\n                return res1 > res2;\n            return a.first < b.first;\n        };\n        pq = customSet(comp);\n        pq.insert(make_pair(-1, N));\n    }\n    \n    int seat() {\n        int ans = -1;\n        auto tmp = *pq.begin();\n        pq.erase(pq.begin());\n        \n        if (tmp.first == -1) {\n            ans = 0;\n        } else if (tmp.second == N) {\n            ans = N-1;\n        } else {\n            ans = (tmp.first + tmp.second) / 2;\n        }\n        auto it1 = pq.insert(make_pair(tmp.first, ans)).first;\n        auto it2 = pq.insert(make_pair(ans, tmp.second)).first;\n        \n        indexes[ans] = make_pair(it1, it2);\n        indexes[tmp.first].second = it1;\n        indexes[tmp.second].first = it2;\n        \n        return ans;\n    }\n    \n    void leave(int p) {\n        auto removal = indexes[p];\n        indexes.erase(p);\n        auto it = pq.insert(make_pair(removal.first->first, removal.second->second)).first;\n        indexes[removal.first->first].second = it;\n        indexes[removal.second->second].first = it;\n        \n        pq.erase(removal.first);\n        pq.erase(removal.second);\n    }\n};\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom* obj = new ExamRoom(N);\n * int param_1 = obj->seat();\n * obj->leave(p);\n */\n```
[]