写过的裸题,还敲了半天。。。太蒻
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 220
int n,m,num;
double aa[N],ans;
struct Lines{
double x,y1,y2;bool f;//0--del 1--add
}a[N];
inline bool cmp(Lines x,Lines y){
return x.x==y.x?x.f>y.f:x.x<y.x;
}
struct node{
double len,clen;int cov;
}tree[N<<2];
inline void pushup(int p){
if(tree[p].cov) tree[p].clen=tree[p].len;
else tree[p].clen=tree[p<<1].clen+tree[p<<1|1].clen;
}
void build(int p,int l,int r){
tree[p].cov=0;tree[p].clen=0;
if(l==r){tree[p].len=aa[l+1]-aa[l];return;}
int mid=l+r>>1;
build(p<<1,l,mid);build(p<<1|1,mid+1,r);
tree[p].len=tree[p<<1].len+tree[p<<1|1].len;
}
void change(int p,int l,int r,int x,int y,int val){
if(x<=l&&r<=y){
tree[p].cov+=val;
if(tree[p].cov==1) tree[p].clen=tree[p].len;
if(tree[p].cov==0){
if(l==r) tree[p].clen=0;
else pushup(p);
}return;
}
int mid=l+r>>1;
if(x<=mid) change(p<<1,l,mid,x,y,val);
if(y>mid) change(p<<1|1,mid+1,r,x,y,val);
pushup(p);
}
int main(){
// freopen("a.in","r",stdin);
for(int tst=1;;tst++){
scanf("%d",&n);if(!n) break;
if(tst!=1) puts("");m=0;num=0;ans=0;
printf("Test case #%d\n",tst);
for(int i=1;i<=n;++i){
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
a[++num].x=x1;a[num].y1=y1;a[num].y2=y2;a[num].f=1;
a[++num].x=x2;a[num].y1=y1;a[num].y2=y2;a[num].f=0;
aa[++m]=y1;aa[++m]=y2;
}sort(a+1,a+num+1,cmp);
sort(aa+1,aa+m+1);m=unique(aa+1,aa+m+1)-aa-1;build(1,1,m-1);
for(int i=1;i<=num;++i){
ans+=(a[i].x-a[i-1].x)*tree[1].clen;
change(1,1,m-1,lower_bound(aa+1,aa+m+1,a[i].y1)-aa,lower_bound(aa+1,aa+m+1,a[i].y2)-aa-1,a[i].f?1:-1);
}
printf("Total explored area: %.2lf\n",ans);
}
return 0;
}