zoukankan      html  css  js  c++  java
  • 【HDU】3265 Posters

      1 #include<cstdio>
      2 #include<cstring>
      3 #include<cstdlib>
      4 #define MAXN 50010
      5 typedef __int64 LL;
      6 struct Line
      7 {
      8     int left,right,high,flag;
      9 };
     10 struct node
     11 {
     12     int cover,len;
     13 };
     14 Line p[MAXN<<3];
     15 node tree[MAXN<<5];
     16 int cnt,x[MAXN<<3];
     17 inline void Post(int x1,int y1,int x2,int y2)
     18 {
     19     if(x1!=x2&&y1!=y2)
     20     {
     21         x[cnt]=x1;
     22         p[cnt].left=x1;
     23         p[cnt].right=x2;
     24         p[cnt].high=y1;
     25         p[cnt++].flag=1;
     26         x[cnt]=x2;
     27         p[cnt].left=x1;
     28         p[cnt].right=x2;
     29         p[cnt].high=y2;
     30         p[cnt++].flag=-1;
     31     }
     32 }
     33 int cmp1(const void *a,const void *b)
     34 {
     35     return *(int *)a-*(int *)b;
     36 }
     37 int cmp2(const void *a,const void *b)
     38 {
     39     return (*(Line *)a).high-(*(Line *)b).high;
     40 }
     41 int Bin(int val,int low,int high)
     42 {
     43     int mid;
     44     while(low<high)
     45     {
     46         mid=(low+high)>>1;
     47         if(x[mid]==val)
     48             return mid;
     49         if(x[mid]<val)
     50             low=mid+1;
     51         else
     52             high=mid;
     53     }
     54 }
     55 void Build(int L,int R,int rt)
     56 {
     57     tree[rt].len=tree[rt].cover=0;
     58     if(L!=R)
     59     {
     60         int mid=(L+R)>>1;
     61         Build(L,mid,rt<<1);
     62         Build(mid+1,R,rt<<1|1);
     63     }
     64 }
     65 inline void PushUp(int L,int R,int rt)
     66 {
     67     if(tree[rt].cover)
     68         tree[rt].len=x[R+1]-x[L];
     69     else if(L==R)
     70         tree[rt].len=0;
     71     else
     72         tree[rt].len=tree[rt<<1].len+tree[rt<<1|1].len;
     73 }
     74 void Update(int st,int en,int flag,int L,int R,int rt)
     75 {
     76     if(st<=L&&R<=en)
     77     {
     78         tree[rt].cover+=flag;
     79         PushUp(L,R,rt);
     80     }
     81     else
     82     {
     83         int mid=(L+R)>>1;
     84         if(mid>=st)
     85             Update(st,en,flag,L,mid,rt<<1);
     86         if(en>mid)
     87             Update(st,en,flag,mid+1,R,rt<<1|1);
     88         PushUp(L,R,rt);
     89     }
     90 }
     91 int main()
     92 {
     93     LL ans;
     94     int i,n,m,st,en,x1,y1,x2,y2,x3,y3,x4,y4;
     95     while(scanf("%d",&n),n)
     96     {
     97         for(cnt=i=0;i<n;i++)
     98         {
     99             scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    100             Post(x1,y1,x2,y3);
    101             Post(x1,y4,x2,y2);
    102             Post(x1,y3,x3,y4);
    103             Post(x4,y3,x2,y4);
    104         }
    105         qsort(x,cnt,sizeof(x[0]),cmp1);
    106         qsort(p,cnt,sizeof(p[0]),cmp2);
    107         for(i=m=0;i<cnt;i++)
    108         {
    109             if(x[i]!=x[m])
    110                 x[++m]=x[i];
    111         }
    112         Build(0,m,1);
    113         for(ans=i=0;i<cnt-1;i++)
    114         {
    115             st=Bin(p[i].left,0,m+1);
    116             en=Bin(p[i].right,0,m+1);
    117             Update(st,en-1,p[i].flag,0,m,1);
    118             ans+=(LL)(p[i+1].high-p[i].high)*tree[1].len;
    119         }
    120         printf("%I64d\n",ans);
    121     }
    122     return 0;
    123 }
    新博客:www.zhixiangli.com
  • 相关阅读:
    (转)Hadoop MapReduce链式实践--ChainReducer
    (转)Permission denied: win7下面eclipse上传本地文件到DFS && 运行M/R程序时出现的同样的错误解决方法
    为什么需要注册OCX控件?
    WPF插件开发:使用FrameworkElementAdapters时VS报错的问题
    C# semphore的使用
    C# int可以表示的最大值
    WCF客户端从服务器下载数据
    C# 读取WAV文件(详细)
    C#读取wav文件
    VEMap.DeleteAllShapeLayers 方法
  • 原文地址:https://www.cnblogs.com/DrunBee/p/2529261.html
Copyright © 2011-2022 走看看