P8889求助 不知道二分哪里错了
查看原帖
P8889求助 不知道二分哪里错了
835857
91xrz楼主2023/7/21 09:33

后面70%过不了。。

#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
long long n, m, cnt,ans;
long long a[N];
long long b[N];
bool is_ture;
bool check(int x)
{
	int l=0,r=m+1;
	while (l + 1 != r)
	{
		int mid = (l + r) / 2;
		if (b[mid] >= x)
			r = mid;
		else l = mid;
	}
	return b[r] == x;//r为第一个大于等于x的数 判断r是否等于x
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=m;i++)
		cin >> b[i];
	sort(b+1,b+1+m);

	for (int i = 1; i <= n; i++)
	{
		if (check(a[i]))
		{
			if (is_ture)
				is_ture = false;
		}

		else if (is_ture == 0)
		{
			is_ture = 1;
			cnt++;
		}
	}
	cout << cnt;
}

感觉是数据范围的问题?不知道咋解决

2023/7/21 09:33
加载中...