zzhtxwd @ 2024-10-16 20:34:47
#include<stdio.h>
int main()
{int m,n;
scanf("%d%d",&n,&m);
int numbers[100000]={0};
int arr[1000000]={0};
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
int nums[100000]={0};
for(int i=0;i<m;i++)
scanf("%d",&nums[i]);
int begin=0,end=n-1;
for(int i=0;i<m;i++)
{int target=nums[i];
int left=-1;
while(begin<=end)
{int middle=(begin+end)/2;
if(arr[middle]>target)
{
end=middle-1;
}
else if(arr[middle]<target)
{
begin=middle+1;
}
else
{
end=middle-1;
left=middle;
}
}
numbers[i]=left;
}
for(int i=0;i<m;i++)
{
printf("%d ",numbers[i]);
}
return 0;
}```c
by lzacode @ 2024-10-16 21:04:56
@zzhtxwd 奇怪的马蜂
by zzhtxwd @ 2024-10-16 21:13:31
我会了