type Fenwick struct { tree []int } func NewFenwick(n int) *Fenwick { return &Fenwick{ tree: make([]int, n), } } func (f *Fenwick) Sum(i int) int { sum := 0 for i != 0 { sum += f.tree[i] i &= i - 1 } return sum } func (f *Fenwick) Add(i, add int) { if i == 0 { f.tree[0] += add return } for { f.tree[i] += add i += i & -i if i >= len(f.tree) { return } } }
To receive a hint, submit unfixed code.