• <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>

            HDOJ 1698 Just A Hook 線段樹

            Problem Description
            In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.



            Now Pudge wants to do some operations on the hook.

            Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
            The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:

            For each cupreous stick, the value is 1.
            For each silver stick, the value is 2.
            For each golden stick, the value is 3.

            Pudge wants to know the total value of the hook after performing the operations.
            You may consider the original hook is made up of cupreous sticks.
             

            Input
            The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
            For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
            Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
             

            Output
            For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
             

            Sample Input
            1
            10
            2
            1 5 2
            5 9 3
             

            Sample Output
            Case 1: The total value of the hook is 24.
             

            Source

            #include <iostream>
            using namespace std;

            const int MAXN = 100001;
            struct segment{
                
            int left,right,color;
                
            bool cover;
            }
            tree[MAXN*3];

            void create(int l,int r,int step){
                tree[step].left
            =l,tree[step].right=r;
                tree[step].color
            =tree[step].cover=1;
                
            if(l==r) return ;
                
            int mid=(l+r)>>1;
                create(l,mid,
            2*step);
                create(mid
            +1,r,2*step+1);
            }

            void update(int l,int r,int c,int step){
                
            if(l==tree[step].left&&r==tree[step].right){
                    tree[step].color
            =c;
                    tree[step].cover
            =1;
                    
            return;
                }

                
            if(tree[step].cover){
                    tree[step].cover
            =0;
                    tree[
            2*step].cover=tree[2*step+1].cover=1;
                    tree[
            2*step].color=tree[2*step+1].color=tree[step].color;
                }

                
            if(r<=tree[2*step].right)
                    update(l,r,c,
            2*step);
                
            else if(l>=tree[2*step+1].left)
                    update(l,r,c,
            2*step+1);
                
            else{
                    update(l,tree[
            2*step].right,c,2*step);
                    update(tree[
            2*step+1].left,r,c,2*step+1);
                }

            }

            int query(int step){
                
            if(tree[step].cover) 
                    
            return tree[step].color*(tree[step].right-tree[step].left+1);
                
            else 
                    
            return query(2*step)+query(2*step+1);
            }

            int main(){
                
            int i,t,n,q,l,r,c;
                scanf(
            "%d",&t);
                
            for(i=1;i<=t;i++){
                    scanf(
            "%d %d",&n,&q);
                    create(
            1,n,1);
                    
            while(q--){
                        scanf(
            "%d %d %d",&l,&r,&c);
                        update(l,r,c,
            1);
                    }

                    printf(
            "Case %d: The total value of the hook is %d.\n",i,query(1));
                }

                
            return 0;
            }

            posted on 2009-05-12 16:32 極限定律 閱讀(516) 評論(1)  編輯 收藏 引用 所屬分類: ACM/ICPC

            評論

            # re: HDOJ 1698 Just A Hook 線段樹 2009-08-13 21:02 zeus

            good 剛剛做了也是1y
            呵呵你寫什么都很詳細啊 學習了  回復  更多評論   

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統計

            常用鏈接

            留言簿(10)

            隨筆分類

            隨筆檔案

            友情鏈接

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            日日狠狠久久偷偷色综合0| 成人综合久久精品色婷婷| 秋霞久久国产精品电影院| 国产精品熟女福利久久AV| 狠狠色丁香婷婷久久综合 | 伊人久久综在合线亚洲2019| 久久精品无码一区二区三区免费| 欧美日韩久久中文字幕| 91超碰碰碰碰久久久久久综合| 综合久久精品色| 99久久精品免费国产大片| 麻豆亚洲AV永久无码精品久久| 精品久久久久久无码人妻热| 久久久久亚洲AV成人片| 国产精品久久久久免费a∨| 99久久99久久精品国产片果冻| 乱亲女H秽乱长久久久| 亚洲午夜久久久| 香蕉99久久国产综合精品宅男自 | 精品无码久久久久国产动漫3d| 亚洲国产精品久久久久网站| 色婷婷综合久久久久中文一区二区 | 日韩欧美亚洲国产精品字幕久久久| 久久99精品久久久久婷婷| 久久笫一福利免费导航| 精品久久久久久国产三级| 国产成人精品综合久久久| 国产亚洲欧美成人久久片| 久久精品亚洲精品国产色婷| 亚洲精品乱码久久久久久蜜桃图片| 超级碰碰碰碰97久久久久| 久久久久人妻精品一区三寸蜜桃| 99久久精品免费国产大片| 中文字幕亚洲综合久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久久久久久久无码精品亚洲日韩 | 狠狠色丁香久久婷婷综合蜜芽五月| 久久激情亚洲精品无码?V| 精品久久久久久久久久中文字幕| 久久99热这里只有精品国产| 久久天天躁狠狠躁夜夜不卡|