AcWing 3688. 集合交并
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e6 + 10;
int t, n, m, k, l, r, op, x, y;
unordered_set<int> st, st2;
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x;
st.insert(x);
}
for (int j = 1; j <= m; j++) {
cin >> x;
st2.insert(x);
}
// 3 4 7
// 2 3 4 6
int cnt1 = 0, cnt2 = 0;
for (int num : st) {
if (st2.count(num)) {
cnt1++;
}else{
cnt2++;
}
}
cout<<cnt1<<" "<<st2.size()+cnt2;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}