Advertisement
Ritam_C

Ball in Berland Codeforces

Feb 18th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long int
  4. #define ld long double
  5. #define pb push_back
  6. #define p_b pop_back
  7. #define si stack<int>
  8. #define sll stack<ll>
  9. #define sc stack<char>
  10. #define vi vector<int>
  11. #define vll vector<ll>
  12. #define mii map<int, int>
  13. #define msi map<string, int>
  14. #define mci map<char, int>
  15. #define qc queue<char>
  16. #define qi queue<int>
  17. #define qll queue<ll>
  18. using namespace std;
  19.  
  20. int main(){
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(NULL);
  23.     int t;
  24.     cin >> t;
  25.     while(t--){
  26.         ld a, b, k;
  27.         cin >> a >> b >> k;
  28.         ld tot = k*(k-1)/2;
  29.         map<ld, ld> boys, girls;
  30.         for(int i = 0; i < k; i++){
  31.             ld x;
  32.             cin >> x;
  33.             boys[x]++;
  34.         }
  35.         for(int i = 0; i < k; i++){
  36.             ld x;
  37.             cin >> x;
  38.             girls[x]++;
  39.         }
  40.  
  41.         if(tot == 0){
  42.             cout << "0\n";
  43.         } else{
  44.             for(auto i = boys.begin(); i != boys.end(); i++){
  45.                 if(i->second > 1){
  46.                     tot -= (i->second)*(i->second-1)/2;
  47.                 }
  48.             }
  49.             for(auto i = girls.begin(); i != girls.end(); i++){
  50.                 if(i->second > 1){
  51.                     tot -= (i->second)*(i->second-1)/2;
  52.                 }
  53.             }
  54.  
  55.             cout << fixed << setprecision(0) << tot << "\n";
  56.         }
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement