Go golang binary indexed tree
when it involves add and sub of line segments, we think of binary indexed tree.\n\nfunc minMoves(nums []int, limit int) int {\n    n := len(nums)\n    t := &BIT
when it involves add and sub of line segments, we think of binary indexed tree.\n```\nfunc minMoves(nums []int, limit int) int {\n    n := len(nums)\n    t := &BIT{\n        tree: make([]int, 2 * limit + 1),\n        l: 2 * limit + 1,\n    }\n    \n    for i := 0; i < n / 2; i++ {\n\t// a ...(2)... b ...(1)... c(0) ...(1)... d ...(2)... e\n        a := 2\n        b := min(nums[i], nums[n - i - 1]) + 1\n        c := nums[i] + nums[n - i - 1]\n        d := max(nums[i], nums[n - i - 1]) + limit\n   //     e := 2 * limit\n        t.add(a, 2)\n        t.add(b, -1)\n        t.add(d + 1, 1)\n        t.add(c, -1)\n        t.add(c + 1, 1)\n    }\n    \n    res := n\n    for i := 2; i <= 2 * limit; i++ {\n        res = min(res, t.sum(i))\n    }\n    return res\n}\n\ntype BIT struct {\n    tree []int\n    l int\n}\n\nfunc (t BIT) sum(i int) int {\n    res := 0\n    for i != 0 {\n        res += t.tree[i]\n        i = i & (i - 1)\n    }\n    return res\n}\n\nfunc (t BIT) add(i int, diff int) {\n    for i < t.l {\n        t.tree[i] += diff\n        i = i + i - i & (i - 1)\n    }\n}\n\nfunc max(a int, b int) int {\n    if a > b {\n        return a\n    }\n    return b\n}\n\nfunc min(a int, b int) int {\n    if a < b {\n        return a\n    }\n    return b\n}\n```
[]