Beats 100% users
\n# Code\n\nlet acc = Array(100001).fill(0);\n\n/**\n * @param {number} n\n * @param {number} x\n * @param {number} y\n * @return {number[]}\n */\nvar countOfPa
![image.png](https://assets.leetcode.com/users/images/874f345e-f31b-4820-81a5-504e5068fce7_1713475257.6472247.png)\n# Code\n```\nlet acc = Array(100001).fill(0);\n\n/**\n * @param {number} n\n * @param {number} x\n * @param {number} y\n * @return {number[]}\n */\nvar countOfPairs = function (n, x, y) {\n  let res = new Uint32Array(n);\n\n  // Just a line\n  if (Math.abs(x - y) <= 1) {\n    for (let i = 0; i < n; ++i) res[i] = (n - i - 1) * 2;\n    return res;\n  }\n\n  acc.fill(0, 0, n + 1);\n  if (x > y) {\n    let t = x;\n    x = y;\n    y = t;\n  }\n  if (x - 1 > n - y) {\n    let t = n - y + 1;\n    y = n - x + 1;\n    x = t;\n  }\n\n  // Both on the loop\n  let c = y - x + 1;\n  let h = (y - x) >> 1;\n  acc[1] += 2 * c;\n  acc[h + 1] -= 2 * c;\n\n  if ((c & 1) == 0) {\n    acc[c >> 1] += c\n    acc[(c >> 1) + 1] -= c\n  }\n\n  // Both on the arms\n  let la = x - 1;\n  let ra = n - y;\n  if (la) {\n    acc[1] += (la - 1) << 1;\n    for (let i = 2; i <= la; ++i) {\n      acc[i] -= 2;\n    }\n  }\n  if (ra) {\n    acc[1] += (ra - 1) << 1;\n    for (let i = 2; i <= ra; ++i) {\n      acc[i] -= 2;\n    }\n  }\n  for (let i = 1; i <= la; ++i) {\n    acc[i + 2] += 2;\n    acc[i + 2 + ra] -= 2;\n  }\n\n  // One on the loop and one on the arm\n  for (let i = 1; i <= la; ++i) {\n    acc[i] += 2;\n    acc[i + h + 1] -= 2;\n    acc[i + 1] += 2;\n    acc[i + h + 1 + ((c & 1) ^ 1)] -= 2;\n  }\n  for (let i = 1; i <= ra; ++i) {\n    acc[i] += 2;\n    acc[i + h + 1] -= 2;\n    acc[i + 1] += 2;\n    acc[i + h + 1 + ((c & 1) ^ 1)] -= 2;\n  }\n\n  res[0] = acc[1];\n  for (let i = 1; i < n; ++i) {\n    res[i] = res[i - 1] + acc[i + 1];\n  }\n  return res;\n};\n```
['JavaScript']