c++ | easy | faster and easy
\n\n# Code\n\nstruct IntV\n{\n    static int N;\n    int l, r;\n    IntV(int l, int r) : l(l), r(r) {}\n    int getD() const\n    {\n        if(l == 0) return r
\n\n# Code\n```\nstruct IntV\n{\n    static int N;\n    int l, r;\n    IntV(int l, int r) : l(l), r(r) {}\n    int getD() const\n    {\n        if(l == 0) return r;\n        if(r == N - 1) return N - 1 - l;\n        if(r < l) return -1;\n        else return (r - l) / 2;\n    }\n    int getP() const\n    {\n        if(l == 0) return 0;\n        if(r == N - 1) return N - 1;\n        else return l + (r - l) / 2;\n    }\n    bool operator < (const IntV& a) const\n    {\n        int d1 = getD(), d2 = a.getD();\n        if(d1 != d2) return d1 > d2;\n        return l < a.l;\n    }\n};\n\nint IntV :: N = 0;\n\nclass ExamRoom {\npublic:\n    set<IntV> tab;\n    map<int, int> l2r, r2l;\n    \n    ExamRoom(int N)\n    {\n        IntV :: N = N;\n        tab.clear(); l2r.clear(); r2l.clear();\n        tab.insert(IntV(0, N - 1));\n        l2r[0] = N - 1;\n        r2l[N - 1] = 0;\n    }\n    \n    int seat()\n    {\n        IntV cur = *(tab.begin());\n        tab.erase(tab.begin());\n        \n        int pos = cur.getP();\n        tab.insert(IntV(cur.l, pos - 1));\n        tab.insert(IntV(pos + 1, cur.r));\n        l2r[cur.l] = pos - 1; r2l[pos - 1] = cur.l;\n        l2r[pos + 1] = cur.r; r2l[cur.r] = pos + 1;\n        return pos;\n    }\n    \n    void leave(int p)\n    {\n        int l = r2l[p - 1], r = l2r[p + 1];\n        tab.erase(IntV(l, p - 1));\n        tab.erase(IntV(p + 1, r));\n        tab.insert(IntV(l, r));\n        l2r[l] = r; r2l[r] = l;\n        r2l.erase(p - 1); l2r.erase(p + 1);\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```
['C++']