人有点麻
#include<iostream>
using namespace std;
int main()
{
int n = 0, m = 0;
cin >> n >> m;
int arr[100000];
for (int i = 0; i < n; i++)//放进到原数组中
{
cin >> arr[i];
}
int arr1[100000];//放一个比较数组
for (int i = 0; i < m; i++)
{
cin >> arr1[i];
}
int x = 0, y = n;//变成数组的范围内
int k = 0,j=0;
for(int i=0;i<m;i++)//询问次数
{
x = 0, y = n;
while (x < y)
{
j = x + (y - x >> 1);//中点一直在更新
if (arr[j] >= arr1[k])
{
y = j;
}
else if (arr[j] < arr1[k])
{
x = j + 1;
}
}
if (x == y && arr[x] != arr1[k])
{
k++;
if (k == m)
{
cout << "-1";
}
else
{
cout << "-1" << " ";
}
}
else
{
k++;
cout<< x+1<<" ";
}
}
return 0;
}