1. 程式人生 > >【模板】樹狀樹組

【模板】樹狀樹組

 

template<typename T> struct BIT {
	T *s; int lim;
	void init(int x) { lim = x, s = new T[x + 1], memset(s, 0, (lim + 1) * sizeof(int)); }
	void update(int x, T c) { for(;x <= lim; x += x & -x)s[x] += c; }
	T query(int x) { T ans = 0; for(; x; x -= x & -x)ans += s[x]; return ans; }
};