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

            最新隨筆

            搜索

            最新評論

            獨立博客: 哲學與程序
            狠狠狠色丁香婷婷综合久久五月| 精品国产乱码久久久久久1区2区| 色综合久久天天综合| 久久这里只有精品首页| 国产精品成人99久久久久| 久久伊人中文无码| 久久人人爽人人爽人人AV东京热| 国产精品久久久久天天影视 | 久久综合久久鬼色| 亚洲中文字幕无码一久久区| 久久久国产精品福利免费| 久久亚洲av无码精品浪潮| 狠狠色丁香久久婷婷综合五月| 精品久久久久久国产牛牛app| 少妇精品久久久一区二区三区| 精品国产福利久久久| 99久久无色码中文字幕人妻| 国产午夜福利精品久久| 久久av无码专区亚洲av桃花岛| 久久亚洲天堂| 久久免费观看视频| 精品国产福利久久久| 人妻少妇久久中文字幕一区二区 | 国内精品久久久久影院亚洲| 久久精品视频免费| 久久久久99精品成人片直播| 久久久午夜精品| 午夜精品久久久久久影视777| 久久夜色tv网站| 国产成人久久激情91| 久久久免费精品re6| 色综合久久久久久久久五月| 久久91精品国产91久| 四虎亚洲国产成人久久精品| 久久久久99精品成人片牛牛影视| 精品久久久久久亚洲| 久久成人影院精品777| 久久精品国产免费| 久久er热视频在这里精品| 丁香久久婷婷国产午夜视频| 大美女久久久久久j久久|