标签:des style blog http io ar color os sp
2 0 0 10 10 1 1 9 9 2 2 8 8 3 3 7 7 0
56
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 100000; 18 struct node{ 19 int lt,rt,cnt,len; 20 }; 21 struct Line{ 22 int lx,rx,h,delta; 23 Line(int x = 0,int y = 0,int z = 0,int d = 0){ 24 lx = x; 25 rx = y; 26 h = z; 27 delta = d; 28 } 29 bool operator<(const Line &b) const{ 30 return h < b.h; 31 } 32 }; 33 node tree[maxn<<2]; 34 Line line[maxn<<2]; 35 int tot; 36 void build(int lt,int rt,int v){ 37 tree[v].lt = lt; 38 tree[v].rt = rt; 39 tree[v].cnt = tree[v].len = 0; 40 if(lt + 1 == rt) return; 41 int mid = (lt + rt)>>1; 42 build(lt,mid,v<<1); 43 build(mid,rt,v<<1|1); 44 } 45 void pushup(int v){ 46 if(tree[v].cnt) tree[v].len = tree[v].rt - tree[v].lt; 47 else if(tree[v].lt + 1 == tree[v].rt) tree[v].len = 0; 48 else tree[v].len = tree[v<<1].len + tree[v<<1|1].len; 49 } 50 void update(int lt,int rt,int v,int delta){ 51 if(tree[v].lt >= lt && tree[v].rt <= rt){ 52 tree[v].cnt += delta; 53 pushup(v); 54 return; 55 } 56 if(lt < tree[v<<1].rt) update(lt,rt,v<<1,delta); 57 if(rt > tree[v<<1|1].lt) update(lt,rt,v<<1|1,delta); 58 pushup(v); 59 } 60 int main() { 61 int n,x1,y1,x2,y2,x3,y3,x4,y4; 62 while(scanf("%d",&n),n){ 63 build(0,50010,1); 64 for(int i = tot = 0; i < n; ++i){ 65 scanf("%d %d %d %d",&x1,&y1,&x2,&y2); 66 scanf("%d %d %d %d",&x3,&y3,&x4,&y4); 67 line[tot++] = Line(x1,x4,y4,1); 68 line[tot++] = Line(x1,x4,y2,-1); 69 line[tot++] = Line(x4,x2,y3,1); 70 line[tot++] = Line(x4,x2,y2,-1); 71 line[tot++] = Line(x3,x2,y1,1); 72 line[tot++] = Line(x3,x2,y3,-1); 73 line[tot++] = Line(x1,x3,y1,1); 74 line[tot++] = Line(x1,x3,y4,-1); 75 } 76 sort(line,line+tot); 77 LL sum = 0; 78 for(int i = 0; i+1 < tot; ++i){ 79 update(line[i].lx,line[i].rx,1,line[i].delta); 80 sum += (LL)tree[1].len*(line[i+1].h - line[i].h);//这个地方有点坑啊。。注意溢出。。 81 } 82 cout<<sum<<endl; 83 } 84 return 0; 85 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/crackpotisback/p/4118524.html