[hoj 2678]Stars[二维树状数组]

二维树状数组的含义:

sum[i][j]表示从lowbit(i)<=x<=i,lowbit(j)<=y<=j之间的元素之和.

题意:

类似poj那道Stars,扩展到了三维.


#include 
#include 
#include 
using namespace std;
const int MAXN = 15005;
const int N = 1005;
typedef struct point{
    int x,y,z;
}point;
point p[MAXN];
int c[N][N],s[MAXN];
bool cmp(point a,point b)
{
    if(a.z!=b.z)  return a.z0; i-=lowbit(i))
        for(int j=y; j>0; j-=lowbit(j))
            ans += c[i][j];
    return ans;
}

void add(int x,int y, int v)
{
    for(int i=x;i>n)
    {
        memset(c,0,sizeof(c));
        memset(s,0,sizeof(s));
        for(int i=1;i<=n;i++)
            cin>>p[i].x>>p[i].y>>p[i].z;
        sort(p+1,p+n+1,cmp);
        for(int k=1;k<=n;k++)
        {
            s[GetSum(p[k].x+1,p[k].y+1)]++;
            add(p[k].x+1,p[k].y+1,1);
        }
        for(int i=0;i


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