1 条题解
-
0
C++ :
#include<bits/stdc++.h> using namespace std; #define LL long long const int Maxn = 5005,Maxv = 2e7+5; int A[Maxn] , cnt[Maxv] , C[Maxv]; int N; inline LL C2(int x){return (LL)x*(x-1) / 2;} inline LL C3(int x){return (LL)x*(x-1)*(x-2)/6;} inline LL C4(int x){return (LL)x*(x-1)*(x-2)*(x-3)/24;} int main(){ scanf("%d",&N); for(int i = 1 ; i <= N ; ++i) scanf("%d",&A[i]),cnt[A[i]]++; sort(A + 1 , A + N + 1); LL ans = 0; for(int i = 1 ; i <= N ; ++i){ LL num = cnt[A[i]]; if(A[i] != A[i-1]){ for(int j = i + 1 ; j <= N && A[j] < 2*A[i] ; ++j) if(A[j] != A[j+1]) ans += C2(cnt[A[j]]) * (num * cnt[A[j] - A[i]] * C[A[j]] + C2(num) * C2(cnt[A[j]-A[i]])); ans += C2(cnt[A[i] << 1]) * C4(cnt[A[i]]); } for(int j = i + 1 ; j <= N ; ++j) if(A[j+1] != A[j]) ans += C3(cnt[A[j]])*C[A[j] - A[i]]; for(int j = 1 ; j < i ; ++j) ++C[A[j] + A[i]]; } printf("%lld\n",ans); return 0; }
- 1
信息
- ID
- 1027
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者