Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long N = 2e5 + 5, MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- double t, n, a[N];
- int main() {
- IO
- cin >> t;
- while (t--) {
- map<double, long long>mp;
- map<double, bool>isUsed;
- long long sm = 0;
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- mp[a[i]]++;
- sm += a[i];
- }
- double k = (double)sm / n;
- long long ans = 0;
- for (int i = 1; i <= n; i++) {
- if (isUsed[a[i]])continue;
- double x = (double)sm - a[i] - k * (n - 2);
- if (mp[x])
- if (x == a[i])ans += mp[a[i]] * (mp[a[i]] - 1) / 2;
- else ans += mp[a[i]] * mp[x];
- isUsed[x] = isUsed[a[i]] = 1;
- }
- cout << ans << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment