#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\n",sol(q)); } return 0; }