后面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;
}
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;
}
感觉是数据范围的问题?不知道咋解决