Advertisement
Zuneve

фывфыв

Oct 12th, 2023
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int s = 536870913;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     const int mod = n * n * 4;
  12.     vector<int> A(n), B(n), C(n), D(n);
  13.     for (int i = 0; i < n; i++) {
  14.         cin >> A[i] >> B[i] >> C[i] >> D[i];
  15.     }
  16.     vector<pair<int, int>> hashTable(mod, {s, s});
  17.     for (int i = 0; i < n; i++) {
  18.         for (int j = 0; j < n; j++) {
  19.             int abSum = A[i] + B[j];
  20.             int index = (abSum + s) % mod;
  21.  
  22.             while (hashTable[index].first != abSum && hashTable[index].second != s) {
  23.                 index = (index + 1) % mod;
  24.             }
  25.             if (hashTable[index].second == s) hashTable[index].second = 0;
  26.             hashTable[index] = {abSum, ++hashTable[index].second};
  27.         }
  28.     }
  29.  
  30.     int cnt = 0;
  31.     for (int i = 0; i < n; i++) {
  32.         for (int j = 0; j < n; j++) {
  33.             int cdSum = -(C[i] + D[j]);
  34.             int index = (cdSum + s) % mod;
  35.  
  36.             while (hashTable[index].first != cdSum && hashTable[index].second != s) {
  37.                 index = (index + 1) % mod;
  38.             }
  39.             if (hashTable[index].second != s) cnt += hashTable[index].second;
  40.         }
  41.     }
  42.  
  43.     cout << cnt;
  44.  
  45.     return 0;
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement