Simple BFS
Intuition\nNote: For each position, do some maths to calculate the source and the destination positions of each start postion. Also the positions should have th
# Intuition\nNote: For each position, do some maths to calculate the source and the destination positions of each start postion. Also the positions should have the smae parity.\n\n# Approach\nThe key point is to query/delete the positions instead of querying.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> minReverseOperations(int n, int p, vector<int>& banned, int k) {\n        vector<int> r(n, -1);\n        r[p] = 0;\n        if (k == 1 || n == 1) {\n            return r;\n        }\n        unordered_set<int> all;\n        for (int i = 0; i < n; ++i) {\n            all.insert(i);\n        }\n        all.erase(p);\n        for (int x : banned) {\n            all.erase(x);\n        }\n        vector<set<int>> s(2);\n        for (int x : all) {\n            s[x & 1].insert(x);\n        }\n        queue<int> q;\n        for (q.push(p); !q.empty(); ) {\n            p = q.front();\n            q.pop();\n            // left side:  x \n            // right side: (k - 1 - x)\n            //  p + k - n <= x <= p\n            // max(0, p + k - n) <= x <= min(p, k - 1)\n            const int left = max(0, p + k - n), right = min(p, k - 1);\n            if (left > right) {\n                continue;\n            }\n            const int v1 = k + p - 1 - right - right;\n            const int v2 = k + p - 1 - left - left;\n            const int ind = v1 & 1;\n            for (auto t = s[ind].lower_bound(v1); t != s[ind].end(); ) {\n                if (*t > v2) {\n                    break;\n                }\n                r[*t] = r[p] + 1;\n                q.push(*t);\n                s[ind].erase(t++);\n            }\n            \n        }\n        return r;\n        \n    }\n};\n```
['C++']