zcy30 @ 2024-08-20 12:52:17
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000005];
int n,m;
int find(int x)
{
int l=0,r=n;
while(l+1<=r)
{
int mid=(l+r)/2;
if(a[mid]>=x)r=mid;
else l=mid;
}
if(a[l]==x)return l+1;
else return -1;
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i];
int x;
for(int i=1;i<=m;i++)
{
cin>>x;
int sum=find(x);
printf("%d",sum);
cout<<" ";
}
return 0;
}
by Chy_20245709 @ 2024-08-20 13:01:13
是TLE吗?可以用scanf 空格可以用putchar