二维树状数组模板

int Lowbit(int t)

{

    return t&(-t);

}

void add(int x, int y)

{

    int i=y;

    while(x<=n)

    {

        y=i;

        while(y<=n)

        {

            c[x][y]++;

            y+=Lowbit(y);

        }

        x+=Lowbit(x);

    }

}

int Sum(int x, int y)

{

    int i=y, sum=0;

    while(x>0)

    {

        y=i;

        while(y>0)

        {

            sum+=c[x][y];

            y-=Lowbit(y);

        }

        x-=Lowbit(x);

    }

    return sum;

}

你可能感兴趣的:(树状数组)