{ "Class_Array_tree": { "prefix": "Class_Array_tree", "body": [ "", "template ", "class Array_tree {", " public:", " Array_tree() {}", " Array_tree(int n) { this->n = n, tree = vector(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 tree;", " int lowbit(int x) { return x & -x; }", "};", "" ] } } }