Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int s = 536870913;
- int main() {
- int n;
- cin >> n;
- const int mod = n * n * 4;
- vector<int> A(n), B(n), C(n), D(n);
- for (int i = 0; i < n; i++) {
- cin >> A[i] >> B[i] >> C[i] >> D[i];
- }
- vector<pair<int, int>> hashTable(mod, {s, s});
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- int abSum = A[i] + B[j];
- int index = (abSum + s) % mod;
- while (hashTable[index].first != abSum && hashTable[index].second != s) {
- index = (index + 1) % mod;
- }
- if (hashTable[index].second == s) hashTable[index].second = 0;
- hashTable[index] = {abSum, ++hashTable[index].second};
- }
- }
- int cnt = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- int cdSum = -(C[i] + D[j]);
- int index = (cdSum + s) % mod;
- while (hashTable[index].first != cdSum && hashTable[index].second != s) {
- index = (index + 1) % mod;
- }
- if (hashTable[index].second != s) cnt += hashTable[index].second;
- }
- }
- cout << cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement