10分求助 悬赏1关注
查看原帖
10分求助 悬赏1关注
644394
dongrq_cs楼主2023/7/21 13:55
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n,m,a[N],b[N];
int find(int x){
	int lt = 0,rt = m + 1;
	while(lt + 1 < rt){
		int mid = (lt + rt) / 2;
		if(b[mid] == a[x]){
			return 1;
		}
		if(b[mid - 1] < a[x] && b[mid + 1] > a[x]){
			return 0;
		}
		if(b[mid]  > a[x]){
			rt = mid;//往mid左边找
		}else{
			lt = mid + 1;//往mid右边找
		}
	}
	return 0;
}
int main(){
	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(find(i) == true){
			cout << a[i] << " ";
		}
	}
	return 0;
}
2023/7/21 13:55
加载中...