mxw100 @ 2024-06-10 16:54:12
#include<iostream>
using namespace std;
int a[1000001];
int main()
{
int n,d;
cin>>n>>d;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int b;
int i=1,l=n;
int m=(i+l)/2;
for(int sum=1;sum<=d;sum++)
{
cin>>b;
i=1;
l=n;
m=(i+l)/2;
bool c=true;
if(b>a[n])
{
cout<<"-1";
}
else
{
while(i<=l)
{
if(b==a[m])
{
int h=m;
while(b==a[h-1]&&h-1>=1)
{
h--;
}
cout<<h<<" ";
c=false;
break;
}
else
{
if(b<a[m])
{
l=m-1;
m=(i+l)/2;
}
else if(b>a[m])
{
i=m+1;
m=(i+l)/2;
}
}
}
if(c)
cout<<"-1 ";
}
}
return 0;
}