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

            巢穴

            about:blank

            P2104

            歸并排序+線段樹+二分.
            二分寫的我比較惡心..

            #include <iostream>
            #include 
            <stdio.h>
            using namespace std;

            struct node
            {
                   
            int l,r,t;
            }
            tree[400001];
            const int MAXN=100001;
            int n,qn;
            int num[19][MAXN];

            int top=0;
            void mergesort(int l,int r,int t,int p)
            {
             
            if (l==r)
             
            {
                      
              num[t][l]
            =num[0][l];
              tree[p].t
            =t;
              tree[p].l
            =l;
              tree[p].r
            =r;
              
            return;  
             }

             
            int mid=(l+r)/2;
             mergesort(l,mid,t
            +1,p*2);
             mergesort(mid
            +1,r,t+1,p*2+1); 
             
            int l1=l,r1=mid+1,v=l;
             
            while(v<=r)
             
            {
              
            if ((num[t+1][l1]<num[t+1][r1]||r1>r)&&l1<=mid) {num[t][v++]=num[t+1][l1++];continue;}
              
            if ((num[t+1][r1]<num[t+1][l1]||l1>mid)&&r1<=r) {num[t][v++]=num[t+1][r1++];}
             }

             tree[p].l
            =l;
             tree[p].r
            =r;
             tree[p].t
            =t;
            }

            int find(int l,int r,int value,int p)
            {
             
            int left_=tree[p].l;
             
            int right_=tree[p].r;
             
            int mid=(left_+right_)/2;
             
            int count=0;
             
            if (left_>=l&&right_<=r)
             
            {
              
            int ll=left_,rr=right_,t=tree[p].t;
              
            int mm;
              
            while(ll<rr)
              
            {
                 mm
            =(ll+rr+1)/2;
                 
            if (num[t][mm]<value) ll=mm; else rr=mm-1;     
              }
                   
              count
            =ll-left_;
              
            if (value>num[t][ll]) count++;
              
            return count;
             }

             
            else
             
            {
              
            if (l<=mid) count+=find(l,r,value,p*2);
              
            if (r>=mid+1) count+=find(l,r,value,p*2+1);
             }

             
            return count;
            }

            int main()
            {

                cin
            >>n>>qn;
                
            for (int i=1;i<=n;i++)
                
            {
                 cin
            >>num[0][i];
                }

                top
            ++;
                mergesort(
            1,n,top,1);
                
            for (int i=1;i<=qn;i++)
                
            {
                    
            int l,r,k;
                    cin
            >>l>>r>>k;
                    k
            --;
                    
            int lp=1,rp=n;
                    
            int mid;
                    
            while(lp<rp)
                    
            {
                     mid
            =(lp+rp+1)/2;
                     
            int kk=find(l,r,num[1][mid],1);
                     
            if (kk<=k) lp=mid;
                     
            else rp=mid-1;
                    }


                    cout
            <<num[1][lp]<<endl;
                }

                 
                 
                 system(
            "pause");
                
                
                
            return 0;
            }

            posted on 2009-11-09 12:35 Vincent 閱讀(186) 評論(0)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)結(jié)構(gòu)與算法

            国产巨作麻豆欧美亚洲综合久久| 久久综合狠狠综合久久97色| 久久精品视频一| 久久本道综合久久伊人| 精品久久久久久久国产潘金莲| 久久久亚洲裙底偷窥综合| 久久精品国产亚洲AV香蕉| 久久精品九九亚洲精品天堂| 久久综合九色综合久99| 久久WWW免费人成一看片| 国产精品一区二区久久精品| 久久亚洲中文字幕精品一区| 欧美日韩精品久久免费| 91久久香蕉国产熟女线看| 久久毛片一区二区| 国产精品美女久久久网AV| 亚洲中文久久精品无码ww16 | 亚洲国产成人久久精品影视| 久久综合偷偷噜噜噜色| 国产综合成人久久大片91| 国内精品久久久久久99| 欧洲精品久久久av无码电影| 久久精品国产精品亚洲艾草网美妙 | 精品免费久久久久久久| 久久青青草视频| 亚洲精品第一综合99久久| 久久男人AV资源网站| 中文字幕亚洲综合久久2| 97久久精品无码一区二区| 性欧美丰满熟妇XXXX性久久久 | 国产麻豆精品久久一二三| 久久精品国产男包| 久久久精品久久久久久| 国产精品岛国久久久久| 精品熟女少妇av免费久久| 久久一日本道色综合久久| 国内精品久久久久影院薰衣草| 久久综合久久综合亚洲| 性高湖久久久久久久久AAAAA| 久久精品人妻中文系列| 久久天天躁狠狠躁夜夜不卡|