• <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>
            posts - 74,  comments - 33,  trackbacks - 0
            City Horizon
            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 4976 Accepted: 1195

            Description

            Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.

            The entire horizon is represented by a number line with N (1 ≤ N ≤ 40,000) buildings. Building i's silhouette has a base that spans locations Ai through Bi along the horizon (1 ≤ Ai < Bi ≤ 1,000,000,000) and has height Hi (1 ≤ Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all N buildings.

            Input

            Line 1: A single integer: N
            Lines 2..N+1: Input line i+1 describes building i with three space-separated integers: Ai, Bi, and Hi

            Output

            Line 1: The total area, in square units, of the silhouettes formed by all N buildings

            Sample Input

            4
            2 5 1
            9 10 4
            6 8 2
            4 6 3

            Sample Output

            16

            Hint

            The first building overlaps with the fourth building for an area of 1 square unit, so the total area is just 3*1 + 1*4 + 2*2 + 2*3 - 1 = 16.

            Source


            USACO 2007 Open Silver

            這道題目屬于區(qū)間覆蓋,和count colour那一道題目屬于同一類型,我就偷懶了,就直接把那道題的代碼直接copy過來,
            沒想到在改的時(shí)候,多刪了一句話導(dǎo)致TLE了20+次,很不happy
            主要思路代碼如下:
            void?Build(int?now,int?l,int?r){
            ????ST[now].l
            =l,ST[now].r=r,ST[now].h=0,ST[now].mark=true;
            ????
            if(l+1>=r)return;
            ????
            int?mid=(l+r)>>1;
            ????Build(
            2*now,l,mid);
            ????Build(
            2*now+1,mid,r);????
            ????
            return?;
            }

            void?insert(int?now,int?l,int?r,int?h){????
            ????
            if(ST[now].mark&&ST[now].h>h)return;
            ????
            if(ST[now].mark&&ST[now].l==l&&ST[now].r==r){
            ????????ST[now].h
            =h;return?;
            ????}
            ????
            ????
            if(ST[now].mark&&ST[now].l+1<ST[now].r){
            ????????ST[
            2*now].h=ST[2*now+1].h=ST[now].h;
            ????????ST[
            2*now].mark=ST[2*now+1].mark=true;
            ????????ST[now].mark
            =false;
            ????}

            ????
            int?mid=(ST[now].l+ST[now].r)>>1;
            ????
            if(l>=mid)insert(2*now+1,l,r,h);
            ????
            else?if(r<=mid)insert(2*now,l,r,h);
            ????
            else?{????
            ????????insert(
            2*now,l,mid,h);
            ????????insert(
            2*now+1,mid,r,h);
            ????}
            ????
            ????
            return?;
            }

            posted on 2009-04-08 14:57 KNIGHT 閱讀(110) 評(píng)論(0)  編輯 收藏 引用

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2009年5月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(8)

            隨筆檔案

            文章檔案

            Friends

            OJ

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲国产天堂久久久久久| 久久天天婷婷五月俺也去| 99久久er这里只有精品18| 久久久久人妻一区二区三区 | 久久久亚洲欧洲日产国码二区| 日产精品久久久一区二区| 久久青青草原综合伊人| 无码任你躁久久久久久| 欧洲精品久久久av无码电影| 免费观看成人久久网免费观看| 久久福利片| 国产精品久久久久久吹潮| 国产三级精品久久| 久久久久亚洲av无码专区| 久久久久无码精品| 四虎国产永久免费久久| 欧美激情一区二区久久久| 伊人久久精品线影院| 中文字幕无码免费久久| 久久天天躁狠狠躁夜夜av浪潮 | 99精品久久精品| 久久亚洲精品国产亚洲老地址| 精品国产一区二区三区久久| 人人妻久久人人澡人人爽人人精品| 久久综合久久综合九色| 久久精品国产第一区二区三区 | 欧美亚洲国产精品久久蜜芽| 婷婷伊人久久大香线蕉AV| 久久婷婷色香五月综合激情| 久久久久久一区国产精品| 日韩精品久久久久久| av国内精品久久久久影院| 亚洲国产欧洲综合997久久| 久久久久99这里有精品10| 久久性精品| 久久婷婷五月综合色99啪ak| 婷婷久久综合九色综合98| 欧美精品一本久久男人的天堂| 色偷偷久久一区二区三区| 久久97久久97精品免视看| 亚洲精品高清久久|