ysj_lyh @ 2023-04-04 17:56:10
#include<iostream>
using namespace std;
int a[100001];
int n,m;
int x;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
while(m--)
{
scanf("%d",&x);
int L=1,R=n,mid,f=0;
while(L<=R)
{
mid=(L+R)/2;
if(a[mid]>=x)
R=mid-1;
else if(a[mid]<x)
L=mid+1;
}
if(a[L]==x)
printf("%d ",L);
else
printf("-1 ");
}
return 0;
}
测试数据
在别的OJ上过了
但在洛谷不知道为什么过不了
by rnf5114 @ 2023-04-04 18:31:11
@ysj_lyh
数组a开小了 n≤10的6次方
by rnf5114 @ 2023-04-04 18:36:37
看代码不易,给个关注呗
by ysj_lyh @ 2023-04-07 13:41:47
@liyong5114
谢谢谢
关注了