【模板】树状数组

C++版本:

树状数组

int lowbit(int x) {
	return x & (-x);
}
void add(int x, int k) {
	while (x <= N)c[x] += k, x += lowbit(x);
}
int sum(int x) {
	int res = 0;
	while (x)res += c[x], x -= lowbit(x);
	return res;
}
posted @ 2020-09-13 19:35  pjhui  阅读(95)  评论(0编辑  收藏  举报