树状数组模板复习

树状数组模板复习

#include
using namespace std;

int n;
int lowbit(int x)
{
    return x&(-x);
}

void update(int pos,int val)
{
    while(pos<=n)
    {
        c[pos]+=val;
        pos+=Lowbit(pos);
    }
}
int query(int pos)
{
    int res=0;
    while(pos>0)
    {
        res+=c[pos];
        pos-=Lowbit(pos);
    }
    return res;
}

你可能感兴趣的:(树状数组模板复习)