hdu 3642 体积并

题意:求三个矩形体积的并

链接:点我

枚举z

  1 #include<stdio.h>
  2 #include<iostream>
  3 #include<stdlib.h>
  4 #include<string.h>
  5 #include<algorithm>
  6 #include<vector>
  7 #include<math.h>
  8 #include<map>
  9 #pragma comment(linker, "/STACK:1024000000,1024000000")
 10 using namespace std;
 11 #define maxn 1100
 12 #define mem(a,b) (memset(a),b,sizeof(a))
 13 #define lmin 1
 14 #define rmax len
 15 #define lson l,(l+r)/2,rt<<1
 16 #define rson (l+r)/2+1,r,rt<<1|1
 17 #define root lmin,rmax,1
 18 #define now l,r,rt
 19 #define int_now int l,int r,int rt
 20 #define INF 99999999
 21 #define LL long long
 22 #define mod 10007
 23 #define eps 1e-6
 24 #define zero(x) (fabs(x)<eps?0:x)
 25 #define LL __int64
 26 map<int,int>mp;
 27 int du[maxn*2];
 28 struct lines
 29 {
 30     int x;
 31     int y,yy;
 32     int z,zz;
 33     int leap;
 34     friend bool operator <(const lines &a,const lines &b)
 35     {
 36         return a.x<b.x;
 37     }
 38 } line[maxn*2];
 39 int num[maxn*4*2];
 40 int sum[maxn*4*2];
 41 int kum[maxn*4*2];
 42 int cover[maxn*4*2];
 43 void push_down(int_now)
 44 {
 45 
 46 }
 47 void push_up(int_now)
 48 {
 49     int len=du[r+1]-du[l];
 50     if(cover[rt]==0)
 51     {
 52         num[rt]=num[rt<<1]+num[rt<<1|1];
 53         sum[rt]=sum[rt<<1]+sum[rt<<1|1];
 54         kum[rt]=kum[rt<<1]+kum[rt<<1|1];
 55     }
 56     if(cover[rt]==1)
 57     {
 58         num[rt]=len;
 59         sum[rt]=num[rt<<1]+num[rt<<1|1];
 60         kum[rt]=sum[rt<<1]+sum[rt<<1|1];
 61     }
 62     if(cover[rt]==2)
 63     {
 64         num[rt]=len;
 65         sum[rt]=len;
 66         kum[rt]=num[rt<<1]+num[rt<<1|1];
 67     }
 68     if(cover[rt]>=3)
 69     {
 70         num[rt]=len;
 71         sum[rt]=len;
 72         kum[rt]=len;
 73     }
 74 }
 75 void creat()
 76 {
 77     memset(cover,0,sizeof(cover));
 78     memset(num,0,sizeof(num));
 79     memset(sum,0,sizeof(sum));
 80     memset(kum,0,sizeof(kum));
 81 }
 82 void updata(int ll,int rr,int x,int_now)
 83 {
 84     if(ll>r||rr<l)return;
 85     if(ll<=l&&rr>=r)
 86     {
 87         cover[rt]+=x;
 88         push_up(now);
 89         return;
 90     }
 91     updata(ll,rr,x,lson);
 92     updata(ll,rr,x,rson);
 93     push_up(now);
 94 }
 95 int main()
 96 {
 97     int T,cas;
 98     scanf("%d",&T);
 99     cas=0;
100     while(T--)
101     {
102         cas++;
103         int n,x,y,z,xx,yy,zz;
104         mp.clear();
105         scanf("%d",&n);
106         LL ls=1;
107         du[0]=-1000010;
108         for(int i=1; i<=n; i++)
109         {
110             scanf("%d%d%d%d%d%d",&x,&y,&z,&xx,&yy,&zz);
111             line[i*2-1].x=x;
112             line[i*2-1].y=y;
113             line[i*2-1].yy=yy;
114             line[i*2-1].z=z;
115             line[i*2-1].zz=zz;
116             line[i*2-1].leap=1;
117             line[i*2].x=xx;
118             line[i*2].y=y;
119             line[i*2].yy=yy;
120             line[i*2].z=z;
121             line[i*2].zz=zz;
122             line[i*2].leap=-1;
123             du[ls++]=y;
124             du[ls++]=yy;
125         }
126         sort(line+1,line+n*2+1);
127         sort(du+1,du+ls);
128         int len=1;
129         for(int i=1; i<ls; i++)
130         {
131             if(du[i]!=du[i-1])
132             {
133                 mp[du[i]]=len;
134                 du[len++]=du[i];
135             }
136         }
137         len-=2;
138         LL are=0;
139         int st=0;
140         creat();
141         for(int j=-501; j<501; j++)
142         {
143             st=0;
144             for(int i=1; i<=n*2; i++)
145             {
146                 int l,r;
147                 l=mp[line[i].y];
148                 r=mp[line[i].yy];
149                 if(line[i].z>j||line[i].zz<=j)continue;
150                 LL x,y;
151                 x=(LL)kum[1];
152                 y=(LL)line[i].x-st;
153                 are+=x*y;
154                 updata(l,r-1,line[i].leap,root);
155                 st=line[i].x;
156             }
157         }
158         printf("Case %d: %I64d\n",cas,are);
159     }
160     return 0;
161 }

 

posted @ 2015-05-10 09:48  miao_a_miao  阅读(171)  评论(0编辑  收藏  举报