1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| #include<bits/stdc++.h> using namespace std; #define ll long long const int N = 65555; struct node { int l,r,lazy,sum; }tree[N<<2]; void build(int l,int r,int rt) { if(l==r) { tree[rt].l=tree[rt].r=r; tree[rt].sum=0; tree[rt].lazy=0; return ; } tree[rt].l=l; tree[rt].r=r; tree[rt].lazy=tree[rt].sum=0; build(l,(l+r)/2,rt<<1); build((l+r)/2+1,r,rt<<1|1); } void PushUp(int rt) { if(tree[rt].lazy) { tree[rt].sum=tree[rt].r-tree[rt].l+1; } else if(tree[rt].l==tree[rt].r)tree[rt].sum=0; else tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum; } void Update(int rt,int l,int r,int flag) { if(l<=tree[rt].l&&tree[rt].r<=r) { tree[rt].lazy+=flag; PushUp(rt); return ; } int mid = (tree[rt].l+tree[rt].r)>>1; if(l<=mid)Update(rt<<1,l,r,flag); if(mid<r)Update(rt<<1|1,l,r,flag); PushUp(rt); } struct line{ int x1,x2,y,flag; line(){} line(int a,int b,int c,int d){ x1=a; x2=b; y=c; flag = d; } }nodes[N*8]; int cmp(line a,line b) { if(a.y==b.y)return a.flag>b.flag; return a.y<b.y; } int main(){ int n; while(scanf("%d",&n)!=EOF&&n!=0) { int x1,x2,x3,x4,y1,y2,y3,y4; ll ans=0; int minn = 50000; int maxx = 0; int m = 0; for(int i=0;i<n;i++) { scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); nodes[++m]= line(x1,x3,y1,1); nodes[++m]= line(x1,x3,y2,-1); nodes[++m]= line(x4,x2,y1,1); nodes[++m]= line(x4,x2,y2,-1); nodes[++m]= line(x3,x4,y1,1); nodes[++m]= line(x3,x4,y3,-1); nodes[++m]= line(x3,x4,y4,1); nodes[++m]= line(x3,x4,y2,-1); minn=min(minn,x1); maxx=max(maxx,x2); } sort(nodes+1,nodes+m+1,cmp); build(minn,maxx-1,1); for(int i=1;i<m;i++) { int ql=nodes[i].x1; int qr=nodes[i].x2-1; if(ql<=qr)Update(1,ql,qr,nodes[i].flag); ans+= (long long)tree[1].sum*(nodes[i+1].y-nodes[i].y); } printf("%I64d\n",ans); } }
|