四值零和(二分)

四值零和

#include <bits/stdc++.h>
using namespace std;

const int N = 2510;

int a[N], b[N], c[N], d[N];
int ab[N*N], cd[N*N];

signed main(){
    int n; cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    int cnt = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            ab[cnt] = a[i] + b[j];
            cd[cnt++] = c[i] + d[j];
        }
    }
    
    sort(cd, cd + cnt);
    long long res = 0;
    for(int i = 0; i < cnt; ++i){
        res += upper_bound(cd, cd + cnt, -ab[i]) - lower_bound(cd, cd + cnt, -ab[i]);    
    }
    
    cout << res << endl;
    
    return 0;
}
posted @ 2025-03-28 10:57  awei040519  阅读(20)  评论(0)    收藏  举报