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

            最新隨筆

            搜索

            最新評論

            獨立博客: 哲學與程序
            久久精品人人做人人爽电影| 久久青青草原精品国产软件| 99久久99久久精品国产片果冻 | 久久亚洲中文字幕精品一区| 一本色道久久综合狠狠躁篇| 亚洲AV日韩AV永久无码久久| 热99re久久国超精品首页| 亚洲午夜精品久久久久久app| 午夜精品久久久久久久| 欧美日韩中文字幕久久久不卡| 日产精品久久久一区二区| 中文字幕亚洲综合久久2| 一本色道久久综合狠狠躁| 久久精品国产一区二区电影| 久久国产精品-国产精品| 人妻无码中文久久久久专区| 久久这里有精品视频| 岛国搬运www久久| www性久久久com| 久久人人爽人人爽人人片AV不 | 久久久久久国产精品美女 | 久久精品国产亚洲AV不卡| 国产福利电影一区二区三区,免费久久久久久久精 | 伊人精品久久久久7777| 久久综合视频网站| 日韩精品久久久肉伦网站| 久久久久国产精品熟女影院| 久久精品国产亚洲欧美| 久久精品这里热有精品| 久久人人爽人人人人片av| 国产精品一久久香蕉产线看| 看久久久久久a级毛片| 99久久夜色精品国产网站| 久久婷婷色香五月综合激情| 久久久久亚洲AV无码去区首| 久久国产免费直播| 色偷偷91久久综合噜噜噜噜| 色8激情欧美成人久久综合电| 欧美激情精品久久久久久久| 亚洲国产成人久久综合一区77| 日韩久久久久中文字幕人妻|