代码:
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1000001;
int n,m;
int a[N];
int x,pos=-1;
bool f=0;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=m;i++){
scanf("%d",&x);
pos=-1;
int l=1,r=n;
while(l<=r){
int mid=(l+r)>>1;
if(a[mid]==x){
pos=mid;
f=1;
while(a[pos]==a[pos-1]){
pos--;
}
break;
}
else if(a[mid]<x) l=mid+1;
else r=mid-1;
}
cout<<pos<<" ";
}
return 0;
}