zoukankan      html  css  js  c++  java
  • 考试订错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;
    }
  • 相关阅读:
    jQuery 核心
    Js实现内容向上无缝循环滚动
    浅析CSS postion属性值用法
    JS原生Ajax请求
    详解SQL集合运算
    Windows上开启IIS
    poj 4618 暴力
    hdu 4614 线段树
    poj 3468 线段树
    hdu 1698 线段树成段更新
  • 原文地址:https://www.cnblogs.com/voldemorte/p/7419324.html
Copyright © 2011-2022 走看看