nvim/snippets/lua.json
2024-01-14 19:23:34 +08:00

33 lines
786 B
JSON

{
"Class_Array_tree": {
"prefix": "Class_Array_tree",
"body": [
"",
"template <class T>",
"class Array_tree {",
" public:",
" Array_tree() {}",
" Array_tree(int n) { this->n = n, tree = vector<T>(n + 1); }",
" void add(int id, T key) {",
" for (int i = id; i <= n; i += lowbit(i)) tree[i] += key;",
" }",
"",
" T get_sum(int id) {",
" T sum = 0;",
" for (int i = id; i; i -= lowbit(i)) sum += tree[i];",
" return sum;",
" }",
"",
" T get_sum(int l, int r) { return get_sum(r) - get_sum(l - 1); }",
"",
" private:",
" int n;",
" vector<T> tree;",
" int lowbit(int x) { return x & -x; }",
"};",
""
]
}
}
}