Replace C++ fenwick tree with Java one