sususu_123 @ 2023-11-17 13:15:19
#include<stdio.h>
const int Max=1e6+10;
int N,M,ans[Max];
void er(int q){
int begin=1,end=N,mid;
while(begin<=end){
mid=begin+(end-begin)/2;
if(ans[mid]==q) break;
else if(ans[mid]>q) end=mid-1;
else begin=mid+1;
}
while(ans[mid-1]==q) mid--;
if(ans[mid]==q) printf("%d ",mid);
else printf("-1 ");
return ;
}
int main(){
scanf("%d %d",&N,&M);
for(int i=1;i<=N;i++) scanf("%d",&ans[i]);
for(int i=1;i<=M;i++){
int n;
scanf("%d",&n);
er(n);
}
return 0;
}
求助,#1wa,#6tle,其它ac