C# Splay + Binary Search + BFS
Code\n\npublic class Solution {\n    public int[] MinReverseOperations(int n, int p, int[] banned, int k) {\n        Dictionary<int, int> d = new();\n        So
# Code\n```\npublic class Solution {\n    public int[] MinReverseOperations(int n, int p, int[] banned, int k) {\n        Dictionary<int, int> d = new();\n        SortedSet<int>[] sets = new SortedSet<int>[2];\n        for(int i = 0; i < 2; i++) sets[i] = new SortedSet<int>();\n        for(int i = 0; i < banned.Length; i++) d[banned[i]] = 1;\n        for(int i = 0; i < n; i++) {\n            if(i != p && !d.ContainsKey(i))\n                sets[i % 2].Add(i);\n        }\n        int[] f = new int[n];\n        Array.Fill(f, -1);\n\n        List<int> q = new List<int>();\n        q.Add(p);\n        for(int step = 0; q.Count > 0; step++) {\n            List<int> nq = new List<int>();\n            foreach(int i in q) {\n                f[i] = step;\n                int l = Math.Max(i - k + 1, k - i - 1);\n                int r = Math.Min(i + k - 1, n * 2 - k - i - 1);\n                SortedSet<int> view = new(sets[l % 2].GetViewBetween(l, r));\n                foreach(int it in view) nq.Add(it);\n                sets[l % 2].ExceptWith(view);\n            }\n            q = nq;\n        }\n        return f;\n    }\n}\n```
['C#']