Answers for "binary indexed tree arithmetic coding"

C++
1

binary indexed tree

template<class T> class BIT {

    vector<T> bit;
public:
    BIT (int size) : bit(vector<T>(size+1)) {}
    BIT (vector<T>& v) : bit(vector<T>(v.size()+1)) {
        for (int i = 0; i<v.size(); ++i) {
            update(i, v[i]);
        }
    }
    T sum (int i) {
        ++i;
        T s = 0;
        while (i>0) {
            s += bit[i];
            i -= i&-i;
        }
        return s;
    }
    void update (int i, T u) {
        ++i;
        while (i<bit.size()) {
            bit[i] += u;
            i += i&-i;
        }
    }

};
Posted by: Guest on January-28-2021

Browse Popular Code Answers by Language