hdu 3265 矩形剪块面积并

时间:2023-03-09 16:57:39
hdu 3265 矩形剪块面积并

http://acm.hust.edu.cn/vjudge/problem/10769

给n张海报,在每张海报上剪掉一个矩形,求面积并

hdu 3265 矩形剪块面积并

把剪块的海报分成四个矩形,就是普通的求面积并问题了

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 50000+5
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f #define ls (rt<<1)
#define rs (rt<<1|1) int n,m; int hh[MAXN],col[MAXN<<],len[MAXN<<]; struct node
{
int l,r,x,c;
node(){}
node(int a,int b,int c,int d):l(a),r(b),x(c),c(d){}
bool operator < (const node &b) const
{
return x<b.x;
}
}a[MAXN<<]; void PushUp(int rt,int l,int r)
{
if(col[rt])
{
len[rt] = hh[r+] - hh[l];
}
else if(l==r) len[rt] = ;
else
{
len[rt] = len[ls]+len[rs];
}
} void update(int val,int L,int R,int l,int r,int rt)
{
if(L<=l && r<=R)
{
col[rt] += val;
PushUp(rt,l,r);
return;
}
int mid = (l+r)>>;
if(L <= mid) update(val,L,R,l,mid,ls);
if(R > mid) update(val,L,R,mid+,r,rs);
PushUp(rt,l,r);
} int main()
{
int i,j,k,t,kase=;
while(~sf("%d",&n) && n)
{
int v=;
LL sum = ;
for(i=;i<n;i++)
{
int x1,y1,x2,y2;
int X1,Y1,X2,Y2;
sf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&X1,&Y1,&X2,&Y2);
if(x1!=X1)
{
hh[v] = y1;
a[v++] = node(y1,y2,x1,);
hh[v] = y2;
a[v++] = node(y1,y2,X1,-);
}
if(x2!=X2)
{
hh[v] = y1;
a[v++] = node(y1,y2,X2,);
hh[v] = y2;
a[v++] = node(y1,y2,x2,-);
}
if(y1!=Y1)
{
hh[v] = y1;
a[v++] = node(y1,Y1,X1,);
hh[v] = Y1;
a[v++] = node(y1,Y1,X2,-);
}
if(y2!=Y2)
{
hh[v] = Y2;
a[v++] = node(Y2,y2,X1,);
hh[v] = y2;
a[v++] = node(Y2,y2,X2,-);
}
}
sort(hh,hh+v);
sort(a,a+v);
int d = ;
for(i=;i<v;i++)
{
if(hh[i]!=hh[i-]) hh[d++] = hh[i];
}
mem(len,);
mem(col,);
for(i=;i<v-;i++)
{
int l = lower_bound(hh,hh+d,a[i].l)-hh;
int r = lower_bound(hh,hh+d,a[i].r)-hh-;
update(a[i].c,l,r,,d-,);
sum+=len[]*((long long)a[i+].x-a[i].x);
//pf("%lf %lf\n",sum,len[1]);
}
pf("%I64d\n",sum);
} return ;
}