OoOiii @ 2024-02-25 16:35:26
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=100010;
long long arr[N];
int n,m;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++) scanf("%lld",&arr[i]);
for(int i=0;i<m;i++)
{
long long num;
scanf("%lld",&num);
int l=0,r=n-1;
while(l<r)
{
int mid=l+r>>1;
if(arr[mid]>=num) r=mid;
else l=mid+1;
}
if(arr[l]!=num) printf("-1 ");
else printf("%lld ",l+1);
}
return 0;
}
by xiangzhenze611 @ 2024-02-25 16:53:28
@OoOiii arr数组不用开long long,N 开小了,要开到一百万以上,你只开了十万多一点
by xiangzhenze611 @ 2024-02-25 16:53:42
@OoOiii 求关注
by OoOiii @ 2024-02-25 17:08:34
@xiangzhenze611 太感谢了!