#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#define x first
#define y second
using namespace std;
const int N = 100010, M = N * 2, INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair <int, int> PII;
LL n, m;
LL b[N];
LL x, y;
map <LL, LL> mp;
int main() {
int t;
scanf("%d", &t);
while (t -- ) {
mp.clear();
scanf("%lld%lld%lld", &n, &x, &y);
LL sum = 0, acc = 0;
for (LL i = 1; i <= n; i ++ ) {
scanf("%lld", &b[i]);
sum += b[i] * i;
acc += b[i] * b[i] * i;
mp[b[i]] ++;
}
LL ans = 0;
LL tx = sum - x;
if (sum == x && acc == y) {
for (auto i : mp) {
ans += i.y * (i.y - 1) / 2;
}
}
else if (tx && (acc - y) % tx == 0 ) {
LL ty = (acc - y) / tx;
for (LL i = 1; i <= n; i ++ ) {
LL bj = ty - b[i];
if (b[i] == bj) continue;
LL j = i - tx / (b[i] - bj);
if (j > i && j <= n && b[j] == bj) ans ++;
}
}
printf("%lld\n", ans);
}
return 0;
}
/*
1
6 61 237
1 1 4 5 1 4
*/
ZOJ 4101 Element Swapping
最新推荐文章于 2024-10-20 18:23:51 发布