树状数组

1
2
3
4
5
6
7
8
namespace BIT
{
    int N,c[MAX];
    #define lowbit(i) (i&(-i))
    inline void add(int x,int k) {for(;x<=N;x+=lowbit(x)) c[x]+=k;}
    inline int query(int x) {int res=0; for(;x;x-=lowbit(x)) res+=c[x]; return res;}
    #undef lowbit
}