O(n log n) solution Python
Complexity\n- Time complexity:  The time complexity of this solution is O(n log n) because we are using a SortedSet data structure which has a log n time comple
# Complexity\n- **Time complexity:**  The time complexity of this solution is O(n log n) because we are using a SortedSet data structure which has a log n time complexity for operations like insertion, deletion, and range queries. Additionally, we are iterating over each element in the input array once, so the overall time complexity is O(n log n).\n\n- **Space complexity:**  The space complexity of this solution is O(n) because we are using a deque to store the indices to be processed and an array to store the minimum number of reverse operations needed for each index. Both of these data structures have a space complexity of O(n).\n\n# Code\n```\nfrom collections import deque\nfrom sortedcontainers import SortedSet\n\nclass Solution:\n    def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:\n        even_indices = SortedSet(range(0, n, 2))\n        odd_indices = SortedSet(range(1, n, 2))\n        \n        for b in banned:\n            if b % 2 == 0:\n                even_indices.discard(b)\n            else:\n                odd_indices.discard(b)\n        \n        ans = [-1] * n\n        queue = deque()\n        queue.append(p)\n        ans[p] = 0\n        \n        if p % 2 == 0:\n            even_indices.discard(p)\n        else:\n            odd_indices.discard(p)\n        \n        while queue:\n            current = queue.popleft()\n            l, r = self.get_range(current, n, k)\n            current_set = even_indices if l % 2 == 0 else odd_indices\n            to_remove = []\n            for i in current_set.irange(l, r):\n                ans[i] = ans[current] + 1\n                queue.append(i)\n                to_remove.append(i)\n            for i in to_remove:\n                current_set.discard(i)\n        \n        return ans\n\n    def get_range(self, x: int, n: int, k: int) -> Tuple[int, int]:\n        l = max(x - k + 1, 0)\n        r = min(x, n - k)\n        l = 2 * l + k - 1 - x\n        r = 2 * r + k - 1 - x\n        return l, r\n\n```
['Python3']