ASonea @ 2023-08-20 22:53:57
#include<iostream>
using namespace std;
const int MAXN=1e6+10;//注意范围
long long read(){//快读
long long x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
int a[MAXN];
int main()
{
long long m,n;
cin>>n>>m;
long long l=1,u = n;
for(int i=1;i<=n;i++)a[i]=read();
while(m--)
{
long long nun = read();
if(nun==0)
{
cout<<-1<<" ";
continue;
}
while(l<u)
{
long long mid =(l+u)/2;
if(a[mid]>=nun) u=mid;
else l = mid+1;
}
if(a[l]==nun)cout<<l<<" ";
else cout<<-1<<" ";
l =1;
u = n;
}
}
by Aesyl @ 2023-08-20 22:56:33
@ASonea 要求输出第一次出现的编号
by ASonea @ 2023-08-20 22:57:51
@Daffod_Tequila 解决了,非负整数。我把零排除在外。读题不规范,亲人两行泪
by RainbowSheep_ @ 2023-08-29 11:10:51
完全一样的错误.... 读题不规范,亲人两行泪