题解:给a数组排序一下然后b中用二分查找看哪个相等即可
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int mx = 1e6+5;
int a[mx];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int c;
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
a[n] = 0;
sort(a,a+n);
int ans = 0;
for(int i = 0; i < n; i++){
scanf("%d",&c);
int k = lower_bound(a,a+n,c)-a;
if(a[k] == c)
ans = c;
}
printf("%d\n",ans);
}
return 0;
}