#include <iostream>
using namespace std;
#define int long long
const int N = 1e5 + 5, lim = 100000;
int n, x, tr[N], tot, t, l_low[N], r_low[N], l_up[N], r_up[N], a[N];
int lowbit(int x) { return x & -x; }
int add(int x, int c)
{
for (int i = x; i <= lim; i += lowbit(i))
tr[i] += c;
}
int sum(int x)
{
int res = 0;
for (int i = x; i; i -= lowbit(i))
res += tr[i];
return res;
}
signed main()
{
cin >> t;
while (t--)
{
cin >> n, tot = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 0; i <= lim; i++)
tr[i] = 0;
for (int i = 1; i <= n; i++)
l_low[i] = sum(a[i]), l_up[i] = sum(lim) - sum(a[i] - 1), add(a[i], 1);
for (int i = 0; i <= lim; i++)
tr[i] = 0;
for (int i = n; i; i--)
r_low[i] = sum(a[i]), r_up[i] = sum(lim) - sum(a[i] - 1), add(a[i], 1);
for (int i = 1; i <= n; i++)
tot += l_low[i] * r_up[i] + l_up[i] * r_low[i];
cout << tot << "\n";
}
}
实在没看出来啥问题,也没越界啊