#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, n, m, t[5000005], mod = 100000, k[5000005], cnt;
signed main() {
cin >> T;
while(T--) {
memset(k, 0, sizeof(k));
memset(t, 0, sizeof(t));
cnt = 0;
cin >> n >> m;
for(int i = 1;i <= n;i++) {
int x;
cin >> x;
if(x == 1) continue;
if(t[x % mod] == 0) k[++cnt] = x;
t[x % mod] ++;
}
for(int i = 1;i <= m;i++) {
int x;
cin >> x;
if(x == 1) continue;
t[x % mod] --;
}
int ans =0;
for(int i = 1;i <= cnt;i++) {
if(t[k[i]] != 0) ans += t[k[i]];
}
if(ans != 1) {
cout << "NO" << endl;
}
else cout << "YES" << endl;
}
}
除了 AC 就剩下 RE 了
虽然我这个算法显然超时