• <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,其朋友范圍區(qū)間[Li,Ri],i可能在[Li,Ri]區(qū)間內(nèi)。你每次從右邊發(fā)射子彈,第i顆子彈值為Ki,打中第一個value值大于或等于Ki的敵人,該敵人value值變?yōu)?,其朋友范圍內(nèi)的敵人value值均增加1;但是,如果沒有敵人的value值大于或者等于Ki,則所有敵人value值增加1。求最后敵人中最高的value值。
            解法:線段樹,每個節(jié)點設置一個max、add元素,max表示該區(qū)間上的最大值,add表示該區(qū)間增加的值;實現(xiàn)(1)區(qū)間段元素+1操作,即對應的區(qū)間add+1;(2)對于對某個value值置1,即可將max=-覆蓋該點的所有區(qū)間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 哲學與程序 閱讀(183) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm

            導航

            公告

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

            常用鏈接

            隨筆分類(37)

            隨筆檔案(41)

            Algorithm

            最新隨筆

            搜索

            最新評論

            獨立博客: 哲學與程序
            免费无码国产欧美久久18| 久久精品水蜜桃av综合天堂| 91久久香蕉国产熟女线看| 亚洲国产精品热久久| 久久高清一级毛片| 亚洲精品无码久久久久去q| 青青青国产成人久久111网站| 欧美午夜A∨大片久久| 精品久久久噜噜噜久久久| 99久久免费只有精品国产| 伊人久久成人成综合网222| 99久久婷婷免费国产综合精品| 久久天天日天天操综合伊人av| 久久精品国产亚洲AV麻豆网站| 久久强奷乱码老熟女| 色综合久久中文综合网| 伊人久久大香线蕉亚洲| 亚洲国产综合久久天堂| 2020最新久久久视精品爱| 97久久精品无码一区二区| 无码人妻久久一区二区三区蜜桃 | 久久精品毛片免费观看| 亚洲人成电影网站久久| 久久国产精品免费一区| 久久精品嫩草影院| 国产高潮国产高潮久久久| 亚洲国产精品成人久久| 精品国产日韩久久亚洲| 精品久久久久久国产三级| 99久久人人爽亚洲精品美女| 久久精品一区二区国产| 91精品国产91久久久久福利| 亚洲AV日韩AV天堂久久| 久久久免费精品re6| 丰满少妇人妻久久久久久| 久久久久国产精品熟女影院| 久久精品午夜一区二区福利| 久久ZYZ资源站无码中文动漫| 精品国产乱码久久久久久郑州公司 | 久久99这里只有精品国产| 亚洲国产精品成人AV无码久久综合影院 |