#define lowbit(x) x&-x
//lowbit取二进制最后的10*序列(例:lowbit(1000100)= 100) const int S; int c[S] = {0}; void add(int x, int d){ while(x <= S) c[x] += d,x += lowbit(x); } int sum(int x){ int ret = 0; while(x > 0) ret += c[x], x -= lowbit(x); return ret; }
原文:https://www.cnblogs.com/hanasaki/p/10996581.html