瑾阳2012 @ 2024-01-27 18:56:58
#include<bits/stdc++.h>
using namespace std;
int n,m,x,ans;
long long a[500002];
unordered_map<long long,bool>s;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=m;i++){
cin>>x;
s[x]=1;
}
bool f=0;
for(int i=1;i<=n;i++){
if(s.find(a[i])!=s.end())
f=0;
if(s.find(a[i])==s.end()&&!f){
ans++;
f=1;
}
}
cout<<ans;
return 0;
}
by 73yrw @ 2024-08-28 11:28:56
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
long long n, m, cnt,ans,a[N],b[N];
bool is_ture;
bool check(long long 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;
}
现在回复还来得及吗
by 瑾阳2012 @ 2024-10-01 18:15:18
@73yrw 可以不可以不要直接给正确代码吗(主要想知道自己的代码出了什么问题嘤