• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            POJ 3277 City Horizon

              1 #include <iostream>
              2 #include <algorithm>
              3 #include <cstdio>
              4 using namespace std;
              5 
              6 const int MaxSize=90001;
              7 
              8 struct Node
              9 {    int left,right,mid;
             10     int hight;
             11 };
             12 
             13 
             14 struct Building
             15 {    int left,right,hight;
             16 }b[40001];
             17 bool cmp(Building a,Building b)
             18 {    return a.hight>b.hight;}
             19 
             20 Node itree[3*MaxSize];
             21 
             22 void Build(int l,int r,int num)
             23 {    itree[num].left=l;
             24     itree[num].right=r;
             25     itree[num].mid=(l+r)/2;
             26     itree[num].hight=0;
             27 
             28     if(l+1!=r)
             29     {    Build(l,itree[num].mid,num<<1);
             30         Build(itree[num].mid,r,(num<<1)+1);
             31     }
             32 }
             33 
             34 void Insert(int l,int r,int h,int num)
             35 {    if(itree[num].left==l&&itree[num].right==r)
             36     {    if(h>itree[num].hight)
             37             itree[num].hight=h;
             38         return;
             39     }
             40     if(r<=itree[num].mid)
             41         Insert(l,r,h,num<<1);
             42     else if(l>=itree[num].mid)
             43         Insert(l,r,h,(num<<1)+1);
             44     else
             45     {    Insert(l,itree[num].mid,h,num<<1);
             46         Insert(itree[num].mid,r,h,(num<<1)+1);
             47     }
             48 }
             49 
             50 
             51 int hash[MaxSize];
             52 
             53 long long Calc(int h,int num)
             54 {    if(h>itree[num].hight)
             55         itree[num].hight=h;
             56     if(itree[num].left+1==itree[num].right)
             57     {    return (long long)itree[num].hight*(hash[itree[num].right]-hash[itree[num].left]);
             58     }
             59     return Calc(itree[num].hight,num<<1)+Calc(itree[num].hight,(num<<1)+1);
             60 }
             61 
             62 int BinarySearch(int *from,int *end,int key)
             63 {    int low=0,high=end-from;
             64     int mid=(low+high)/2;
             65     while(low<=high)
             66         if(from[mid]==key)
             67             return mid;
             68         else if(from[mid]>key)
             69         {    high=mid-1;                
             70             mid=(high+low)/2;                
             71         }    
             72         else        
             73         {    low=mid+1;        
             74             mid=(high+low)/2;                
             75         }            
             76     return mid;
             77 }
             78 
             79 
             80 int main()
             81 {
             82     int N;
             83     scanf("%d",&N);
             84     for(int i=0;i<N;i++)
             85     {    scanf("%d%d%d",&b[i].left,&b[i].right,&b[i].hight);
             86         hash[i<<1]=b[i].left;
             87         hash[(i<<1)+1]=b[i].right;
             88     }
             89     int hlen=0;
             90     sort(hash,hash+2*N);
             91     sort(b,b+N,cmp);
             92     for(int i=0;i<2*N-1;i++)
             93         if(hash[i]!=hash[i+1])
             94             hash[++hlen]=hash[i+1];
             95     hlen++;
             96     Build(0,hlen,1);
             97     for(int i=0;i<N;i++)
             98     {    int l=BinarySearch(hash,hash+hlen,b[i].left);
             99         int r=BinarySearch(hash,hash+hlen,b[i].right);
            100         Insert(l,r,b[i].hight,1);
            101     }
            102     cout<<Calc(0,1)<<endl;
            103     //printf("%I64d\n",Calc(0,1));
            104     return 0;    
            105 }

            posted on 2010-08-29 11:42 ZAKIR 閱讀(133) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            隨筆檔案

            文章分類

            文章檔案

            大牛們

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产精品亚洲| 久久综合久久久| 久久久久久精品免费看SSS| 77777亚洲午夜久久多喷| 2020久久精品国产免费| 日韩一区二区三区视频久久| 欧美喷潮久久久XXXXx| 精品久久久久久无码免费| 午夜精品久久久久久中宇| 精品久久国产一区二区三区香蕉 | av色综合久久天堂av色综合在| 77777亚洲午夜久久多喷| 亚洲国产成人久久综合一区77| 99热成人精品热久久669| 青青热久久国产久精品 | 99久久99久久精品国产| 7777久久久国产精品消防器材| 四虎国产精品免费久久5151| 国产成人精品三上悠亚久久| 91久久精品国产91性色也| 久久无码一区二区三区少妇 | 伊人久久大香线蕉AV一区二区| 青青热久久国产久精品 | 色偷偷88欧美精品久久久| 99久久久国产精品免费无卡顿| 久久乐国产综合亚洲精品| 久久性精品| 开心久久婷婷综合中文字幕| 久久精品国产91久久麻豆自制| 人妻无码中文久久久久专区| 伊人久久综合成人网| 国产精品99久久久久久宅男小说| 国产激情久久久久影院| 99久久精品久久久久久清纯| 亚洲精品高清国产一久久| 久久国产精品一区二区| 久久综合九色综合精品| 国产精品成人久久久久三级午夜电影| 久久国产高潮流白浆免费观看| 欧美熟妇另类久久久久久不卡| 男女久久久国产一区二区三区|