This is a programing problem on Codeforces with a difficulty score of 1400.
Its solution is based on the Inclusion-Exclusion principle.
https://codeforces.com/problemset/problem/1475/C
void solve(){
int a, b, k;
cin >> a >> b >> k;
map<pair<int, int>, int> mapp;
map<int, int> boys, girls;
vector<pair<int, int>> couples(k);
for (int i = 0; i < k; ++i){
cin >> couples[i].first;
boys[couples[i].first] ++;
}
for (int i = 0; i < k; ++i){
cin >> couples[i].second;
girls[couples[i].second] ++;
mapp[couples[i]] ++;
}
long long ans = 0;
for (int i = 0; i < k; ++i){
ans += (k - 1);
auto[x, y] = couples[i];
ans -= boys[x] - 1;
ans -= girls[y] - 1;
ans += mapp[{x, y}] - 1;
}
cout << ans / 2 << '\n';
}
标签:Ball,Berland,++,girls,cin,couples,int,ans
From: https://www.cnblogs.com/yxcblogs/p/18038206