题目链接
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
//就是找左端点,没有输出-1
int n;
int q;
int a[1000010];
int main()
{
scanf("%d",&n);
scanf("%d",&q);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
while(q--){
int x;
scanf("%d",&x);
int l=0,r=n-1;
while(l<r){
int mid = l + r >> 1;
if(a[mid] >= x){
r=mid;
}
else l = mid + 1;
}
if(a[l] == x){
printf("%d ",l+1);
}
else printf("-1 ");
}
return 0;
}