为什么二分RE了
查看原帖
为什么二分RE了
1132665
violet1123楼主2024/10/13 17:47
#include<iostream>

using namespace std;

const int N = 100010;
int a[N];

int main()
{
	int n, m,q;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
		
	for (int i = 0; i < m; i++)
	{
		cin >> q;
		int x = 0, y = n  - 1;
		while (x < y )
			{
				int mid = x + y >> 1;
				if (a[mid] >= q) y = mid;
				else x = mid + 1;
			}
		if (a[x] == q) cout << x + 1<< ' ';
		else cout << "-1 ";
	}
	return 0;
}
2024/10/13 17:47
加载中...