20pts悬关大佬求助
查看原帖
20pts悬关大佬求助
763299
Storm_Lightning楼主2023/10/18 00:04
#include<bits/stdc++.h>
using namespace std;
int x,n,m;
int ans;
int a[500010];
int b[500010];
signed main()
{
	//freopen("Medusa.in","r",stdin);
	//freopen("Medusa.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)	
	{
		cin>>a[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	int q=1;
	for(int i=1;i<=n;i++)
	{
		int l=1,r=m;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(b[mid]==a[i])
			{
				cout<<b[mid]<<' ';
				break;
			}
			else if(b[mid]>a[i])
			{
				r=mid-1;
			}
			else 
			{
				l=mid+1;
			}
		}
	}
	return 0;
}
2023/10/18 00:04
加载中...