• <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>
            獨立博客: 哲學與程序

            哲學與程序

            ZOJ@3453

            ZOJ@3453 題目連接
            題意:有N個敵人,排成一排編號為1~n;對于敵人i有一個初始value[i];對于敵人i,其朋友范圍區間[Li,Ri],i可能在[Li,Ri]區間內。你每次從右邊發射子彈,第i顆子彈值為Ki,打中第一個value值大于或等于Ki的敵人,該敵人value值變為1,其朋友范圍內的敵人value值均增加1;但是,如果沒有敵人的value值大于或者等于Ki,則所有敵人value值增加1。求最后敵人中最高的value值。
            解法:線段樹,每個節點設置一個max、add元素,max表示該區間上的最大值,add表示該區間增加的值;實現(1)區間段元素+1操作,即對應的區間add+1;(2)對于對某個value值置1,即可將max=-覆蓋該點的所有區間add累加值+1;(3)查找大于或等于K的最右元素。
            // 2385696      2011-01-14 20:30:00        Accepted      3453      C++      430      6040      redsea
            #include<stdio.h>
            #include
            <string.h>
            #include
            <algorithm>
            using namespace std;
            const int maxn = 100005;
            int fr[maxn], fl[maxn], value[maxn];
            struct node{
                
            int cr,cl;
                
            int r,l;
                
            int max, add;
            }st[maxn
            *2];
            int len;
            int build(int l,int r, int root)
            {
                
            if(l==r){
                    st[root].cr 
            = st[root].cl = -1;
                    st[root].r 
            = r;
                    st[root].l 
            = l;
                    st[root].max 
            = value[l];
                    st[root].add 
            = 0;
                    
            return value[l];
                }
            else{
                    
            int mid = (l+r)/2;
                    st[root].r 
            = r;
                    st[root].l 
            = l;
                    len
            ++;
                    
            int ll = len;
                    st[root].cl 
            = ll;
                    
            int m1 = build(l,mid, ll);
                    len
            ++;
                    
            int rr = len;
                    st[root].cr 
            = rr;
                    
            int m2 = build(mid+1,r,rr);
                    st[root].add 
            = 0;
                    st[root].max 
            = (m1<m2?m2:m1);
                    
            return st[root].max;
                }
            }
            int add(int l, int r, int root)
            {
                
            if(root < 0)return -1000000000;
                
            else if(st[root].l > r || st[root].r < l){
                    
            return -1000000000;
                }
                
            else if(l <= st[root].l && r >= st[root].r){
                    st[root].add
            ++;
                    st[root].max
            ++;
                    
            return st[root].max;
                }
            else{
                    
            int m1 = add(l,r,st[root].cl);
                    
            int m2 = add(l,r,st[root].cr);
                    
            if(m1<m2)m1=m2;
                    
            if(st[root].max < m1+st[root].add)st[root].max = m1+st[root].add;
                    
            return st[root].max;
                }
            }
            int findMax(int x, int root, int a)
            {
                
            if(st[root].r == st[root].l)
                    
            return st[root].l;
                
            else{
                    
            int l = st[root].cl;
                    
            int r = st[root].cr;
                    
            if(st[r].max + a+st[root].add >= x)
                        
            return findMax(x,r,a+st[root].add);
                    
            else
                        
            return findMax(x,l,a+st[root].add);
                }
            }

            int setToOne(int w, int root, int a)
            {
                
            if(st[root].l == st[root].r)
                {
                    st[root].add 
            = 0;
                    st[root].max 
            = -+ 1;
                    
            return st[root].max;
                }
            else{
                    
            int l = st[root].cl;
                    
            int r = st[root].cr;
                    
            if(st[l].l <= w && st[l].r >= w){
                        
            int m1 =setToOne(w,l,a+st[root].add);
                        
            int m2 =st[r].max;
                        st[root].max 
            = (m1<m2?m2:m1)+st[root].add;
                        
            return st[root].max;
                    }
            else{
                        
            int m1 = setToOne(w,r,a+st[root].add);
                        
            int m2 = st[l].max;
                        st[root].max 
            = (m1<m2?m2:m1)+st[root].add;
                        
            return st[root].max;
                    }
                }
            }
            int main()
            {
                
            int n, m, x;
                
            while(scanf("%d",&n)!=EOF)
                {
                    
            for(int i = 1; i <= n; i++){
                        scanf(
            "%d%d%d",value+i,fl+i,fr+i);
                    }
                    len 
            = 0;
                    build(
            1,n,0);
                    scanf(
            "%d",&m);
                    
            while(m--)
                    {
                        scanf(
            "%d",&x);
                        
            if(st[0].max < x){
                            add(
            1,n,0);
                        }
                        
            else{
                            
            int index = findMax(x,0,0);
                            setToOne(index,
            0,0);
                            add(fl[index],fr[index],
            0);
                        }
                    }
                    printf(
            "%d\n",st[0].max);
                }
                
            return 0;
            }


            posted on 2011-01-15 12:34 哲學與程序 閱讀(178) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm

            導航

            公告

            歡迎訪問 http://zhexue.sinaapp.com

            常用鏈接

            隨筆分類(37)

            隨筆檔案(41)

            Algorithm

            最新隨筆

            搜索

            最新評論

            獨立博客: 哲學與程序
            国产精品熟女福利久久AV| 久久国产成人午夜aⅴ影院 | 久久精品www人人爽人人| 久久久无码人妻精品无码| 久久国产高潮流白浆免费观看| 久久香蕉国产线看观看精品yw| 亚洲成色www久久网站夜月| 精品久久香蕉国产线看观看亚洲| 久久93精品国产91久久综合| 2021久久精品免费观看| 久久综合久久综合久久| 久久久精品久久久久影院| 99久久精品免费看国产一区二区三区| 久久久国产精华液| 麻豆成人久久精品二区三区免费 | 久久综合给合综合久久| 一本一道久久综合狠狠老| 99热精品久久只有精品| 久久99热这里只有精品国产| 国产成年无码久久久久毛片| 国产免费久久精品99re丫y| 久久亚洲国产午夜精品理论片| 日韩欧美亚洲综合久久| 久久黄视频| 国产精品99久久不卡| 久久国产精品国产自线拍免费| 香蕉久久久久久狠狠色| 九九久久精品国产| 91秦先生久久久久久久| 国产Av激情久久无码天堂| 国产精品久久久久久久人人看| 久久艹国产| 狠狠久久综合伊人不卡| 国产午夜精品久久久久九九电影| 久久ZYZ资源站无码中文动漫 | 国产人久久人人人人爽| 精品伊人久久久| 女人高潮久久久叫人喷水| 香蕉久久AⅤ一区二区三区| 欧美色综合久久久久久| 热RE99久久精品国产66热|