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

            最新隨筆

            搜索

            最新評論

            獨立博客: 哲學與程序
            久久免费线看线看| 久久精品国产影库免费看| 日韩精品无码久久一区二区三| 久久99精品久久久久久噜噜 | 久久精品人妻中文系列| 久久这里只有精品18| 日本免费一区二区久久人人澡| 久久久久久无码国产精品中文字幕| 亚洲精品99久久久久中文字幕| 国内精品久久久久影院日本| 久久久久国产视频电影| 国产精品久久久久影视不卡| 国产99久久久国产精品小说| 99久久国产主播综合精品| 久久精品无码专区免费青青| 中文字幕无码av激情不卡久久| 国内精品久久久久久野外| 久久狠狠爱亚洲综合影院| 久久九九久精品国产| 久久香蕉综合色一综合色88| 亚洲人成网亚洲欧洲无码久久 | 国产精品久久久久久搜索| 久久婷婷色香五月综合激情| 狠狠人妻久久久久久综合| 97精品国产91久久久久久| 无码人妻久久一区二区三区| 久久久久亚洲AV综合波多野结衣 | 久久午夜无码鲁丝片| 精品久久久久久久国产潘金莲| 久久免费国产精品| 国产精品综合久久第一页| 久久免费国产精品一区二区| 久久综合九色综合精品| 久久福利青草精品资源站免费| 99精品久久精品| 久久精品国产半推半就| 国内精品久久久久影院免费| 亚洲国产精品一区二区久久| 91精品国产色综久久| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区| 影音先锋女人AV鲁色资源网久久|