simple implementation using binary search
Intuition\n Describe your first thoughts on how to solve this problem. \njust nneed to see updates carefully.\n# Approach\n Describe your approach to solving th
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\njust nneed to see updates carefully.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nbinary search, prefix sums\n\n# Complexity\n- Time complexity: nlogn\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#define ll long long\n\nclass Solution {\npublic:\n    vector<ll> countOfPairs(int n, int x, int y) {\n        vector<ll> res(n);\n        res[0] = 2*(n-1);\n        x--;\n        y--;\n        \n        for(int i = 1;  i < n ; i ++) res[i] = res[i-1]-2;\n        \n        vector<ll> pp(n+3,0);\n        \n        \n        if(x == y || abs(x-y) == 1) return res;\n        if(x > y) swap(x , y);\n        \n        for(int i = n-1 ; i >= 0 ; i --)\n        {\n            int d1 = abs(i - (n-1));\n            int d2 = abs(i - x) + 1 + abs(y - (n-1));\n            \n            if(d2 < d1)\n            {\n                    int low = i;\n                    int high = y;\n                    while(low < high)\n                    {\n                        int mid = (low + high)/2;\n                        if(abs(i - x) + 1 + abs(y - (mid)) < abs(i - mid))\n                        {\n                            high = mid;\n                        }\n                        else\n                        {\n                            low = mid+1;\n                        }\n                    }\n                    \n                    if(low < y)\n                    {\n                        \n                        pp[abs(low - i)]-=2;\n                        pp[abs(y-1-i)+1]+=2;\n                        pp[abs(i - x) + 1 + 1]+=2;\n                        pp[ abs(i-x)+1+abs(low - y)+1]-=2;\n                        \n                    }\n                    \n                    pp[abs(y - i)]-=2;\n                    pp[abs(n-1-i)+1]+=2;\n                    pp[abs(i - x) + 1]+=2;\n                    pp[abs(i-x)+1+abs(n-1 - y) + 1]-=2;\n            }\n        }\n        \n        for(int i = 1 ; i < n+3 ; i ++) pp[i] += pp[i-1];\n        for(int i = 0 ; i < n ; i ++) res[i] += pp[i+1];\n        \n        return res;\n    }\n};\n```
['C++']