• 考试订错3---2


    #include<cstdio>
    #include<iostream>
    using namespace std;
    #define inf 1000000007
    #define N 10000010
    char xB[1<<15],*xS=xB,*xTT=xB;
    #define getc() (xS==xTT&&(xTT=(xS=xB)+fread(xB,1,1<<15,stdin),xS==xTT)?0:*xS++)
    #define isd(c) (c>='0'&&c<='9')
    inline int rd(){
        char xchh;
        int xaa;
        while(xchh=getc(),!isd(xchh));(xaa=xchh-'0');
        while(xchh=getc(),isd(xchh))xaa=xaa*10+xchh-'0';return xaa;
    }
    int n,m,a[N],b[N],q;
    void INIT()
    {
        n=rd();m=rd();
        register int i;
        for(i=1;i<=n;++i) a[i]=rd();
        for(i=1;i<=n;++i) b[i]=rd();
    }
    int sol(int x)//询问分数---x排名
    {
        int l=0,r=x,mid;//二分排名
        if(x>n) l=x-n,r=n;//如果超过人数
        while(l<=r)
        {
            mid=l+r>>1;
            int ta=a[mid],tb=b[x-mid];//将a[n+1]=b[n+1]=inf;样例数据体现
            if(ta<tb)
            {
                if(a[mid+1]>tb) return tb;
                else l=mid+1;
            }
            else 
            {
                if(ta<b[x-mid+1]) return ta;
                else r=mid-1;
            }
        }
        return max(a[mid],b[x-mid]);
    }
    int main()
    {
        freopen("queue.in","r",stdin);
        freopen("queue.out","w",stdout);
        INIT();
        a[n+1]=b[n+1]=inf;
        while(m--)
        {
            q=rd();
            printf("%d
    ",sol(q));
        }
        return 0;
    }
  • 相关阅读:
    P2572 [SCOI2010]序列操作
    python学习笔记2
    嗯,python
    ETROBOT——审题
    条件编译
    第三章单片机简介
    模拟输入输出
    arduino库函数1
    arduino相关文献阅读
    Arduino的小灯亮起来~~~
  • 原文地址:https://www.cnblogs.com/voldemorte/p/7419324.html
Copyright © 2020-2023  润新知