#include<iostream>
#include<vector>
using namespace std;
int n, m;
vector<long long>a(1000000, 0);
long long q;
int binarysearch(int begin, int end)
{
if (begin > end)
return EOF;
int mid = (begin + end) / 2;
if (q == a[mid] && (0 == mid || q != a[mid - 1]))
return mid;
else if (q > a[mid])
return binarysearch(mid + 1, end);
else
return binarysearch(begin, mid - 1);
}
int main()
{
int temp;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
{
cin >> q;
temp = binarysearch(0, n - 1);
if (EOF != temp)
temp++;
cout << temp << ' ';
}
return 0;
}
洛谷P2249 【深基13.例1】查找进阶解法
最新推荐文章于 2023-10-15 23:38:42 发布