Last problem solution (Partial sums)
\n# Complexity\n- Time complexity:\nO(n)\n\n\n\n# Code\n\nclass Solution {\npublic:\n\n    Solution()\n    {\n        ios_base::sync_with_stdio(false);\n       
\n# Complexity\n- Time complexity:\nO(n)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n\n    Solution()\n    {\n        ios_base::sync_with_stdio(false);\n        cin.tie(NULL);\n        cout.tie(NULL);\n    }\n\n    vector<long long> countOfPairs(long long n, long long x, long long y) {\n        if(x == y)\n        {\n            vector<long long> ans(n);\n            for (int i = 0; i < n; ++i) {\n                ans[i] = (n - i + - 1ll) * 2;;\n            }\n            return ans;\n        }\n\n        \n        vector<long long> partial(n+1);\n        if(x > y) swap(x, y);\n        for (long long i = 1; i <= x; ++i) {\n            partial[y - i] -= 2ll;\n            partial[n - i + 1] += 2ll;\n\n            partial[y - i - (y - x - 1)] += 2ll;\n            partial[n - y + 1 + y - i - (y - x - 1)] -= 2ll;\n\n        }\n\n        for (long long i = 1; i <= x; ++i) {\n            long long start = x + (y - x + 1) / 2ll + 1;\n            long long end = y - 1;\n\n            partial[start - i] -= 2ll;\n            partial[end + 1 - i] += 2ll;\n\n            long long sss = x - i + 2ll;\n            partial[sss] += 2ll;\n            partial[end - start + 1 + sss] -= 2ll;\n        }\n\n        long long te = x;\n        x = n - y + 1;\n        y = n - te + 1;\n        for (long long i = 1; i <= x; ++i) {\n            int start = x + (y - x + 1) / 2ll + 1;\n            int end = y - 1;\n\n            partial[start - i] -= 2ll;\n            partial[end + 1 - i] += 2ll;\n\n            int sss = x - i + 2ll;\n            partial[sss] += 2ll;\n            partial[end - start + 1 + sss] -= 2ll;\n        }\n\n        for (int i = x + 1; i <= y - 1 ; ++i) {\n            long long val = (2 * i - x + y + 2) / 2;\n            if(val < y)\n            {\n                partial[val - i] -= 2;\n                partial[y - i] += 2;\n\n                partial[i - x +2] += 2;\n                partial[i - x + y - val + 2] -= 2;\n            }\n\n        }\n\n\n\n        for (int i = 1; i <= n ; ++i) {\n            partial[i] += partial[i - 1];\n        }\n        for (int i = 1; i <= n; ++i) {\n            partial[i] += (n-i) * 2ll;\n        }\n        partial[n] = 0;\n        partial.erase(partial.begin());\n        return partial;\n    }\n};\n```
['C++']