//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "树状数组": {
        "prefix": "acm-2.5bit",
        "body": [
            "template<class T> struct BIT {",
            "    int n;",
            "    vector<T> w;",
            "    BIT(int n, auto &in) : n(n), w(n + 1) { // 预处理填值",
            "        for (int i = 1; i <= n; i++) {",
            "            add(i, in[i]);",
            "        }",
            "    }",
            "    void add(int x, T v) {",
            "        for (; x <= n; x += x & -x) {",
            "            w[x] += v;",
            "        }",
            "    }",
            "    T ask(int x) { // 前缀和查询",
            "        T ans = 0;",
            "        for (; x; x -= x & -x) {",
            "            ans += w[x];",
            "        }",
            "        return ans;",
            "    }",
            "    T ask(int l, int r) { // 差分实现区间和查询",
            "        return ask(r) - ask(l - 1);",
            "    }",
            "};"
        ],
        "description": "插入 树状数组"
    }
}