全部WA了,大佬们求助
查看原帖
全部WA了,大佬们求助
336129
qwer0553楼主2020/7/1 07:54
#include <iostream>

using namespace std;

const int N = 1000005;
int n, m, q[N];

int find(int x)
{
	int l = 0, r = n - 1;
	while(l < r)
	{
		int mid = (l + r) / 2;
		if (q[mid] >= x) r = mid;
		else l = mid + 1;
	}

	if (q[l] == x) return l + 1;
	else return -1;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> q[i];

	while (m--)
	{
		int x;
		cin >> x;

		int ans = find(x);

		cout << ans << endl;
	}

	return 0;
}
2020/7/1 07:54
加载中...