和为0的四个值

来源:互联网 发布:曹云金 知乎 编辑:程序博客网 时间:2024/05/17 09:45
// by BNU_LZM#include<cstdio>#include<algorithm>using namespace std;const int maxn = 4010;int a[maxn], b[maxn], c[maxn], d[maxn], w[maxn*maxn];int erfenl(int x, int y, int v){int m;while(x < y){m = x+(y-x)/2;if(w[m] >= v) y = m;else x = m+1;}return  x;}int erfenr(int x, int y, int v){int m;while(x < y){m = x+(y-x)/2;if(w[m] <= v) x = m+1;else y = m;}return  x;}int main(){freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);int n;scanf("%d", &n);for(int i = 1; i <= n; i++) scanf("%d", &a[i]);for(int i = 1; i <= n; i++) scanf("%d", &b[i]);for(int i = 1; i <= n; i++) scanf("%d", &c[i]);for(int i = 1; i <= n; i++) scanf("%d", &d[i]);int cnt = 1;for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)w[cnt++] = a[i]+b[j];sort(w+1, w+cnt);int ans = 0;for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++){int x = c[i]+d[j];int l = erfenl(1, cnt, -x);int r = erfenr(1, cnt, -x);ans += (r-l);}printf("%d\n", ans);return 0;}

0 0
原创粉丝点击