You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1004 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int c[N];
#define lowbit(x) ((x) & -(x))
int get(int x)
{
int ans = 0;
for (; x; x -= lowbit(x)) ans += c[x];
return ans;
}
void inc(int x)
{
for (; x < N; x += lowbit(x)) c[x]++;
}
int main()
{
multiset<int> s;
int T, n, avg;
scanf("%d", &T);
while (T--)
{
memset(c, 0, sizeof(c));
long long ans = 0;
s.clear();
scanf("%d%d", &n, &avg);
for (int i = 1; i <= n; i++) scanf("%d", a + i), a[i] = a[i] - avg + a[i - 1];
vector<pair<int, int>> v(n);
for (int i = 1; i <= n; i++) v[i - 1] = {a[i], -i};
sort(begin(v), end(v));
for (auto &x : v)
{
ans += get(-x.second) + (x.first > 0);
inc(-x.second);
}
printf("%lld\n", ans);
}
return 0;
}