树状数组
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
int n;
int a[N], xs[N], tr[N];
int lowbit(int x)
{
return x & -x;
}
void add(int x, int c)
{
for(int i = x; i <= n; i += lowbit(i))
tr[i] += c;
}
int query(int x)
{
int res = 0;
for(int i = x; i; i -= lowbit(i))
res += tr[i];
return res;
}
int main()
{
cin >> n;
for(int i = 0; i < n; i ++)
{
cin >> a[i];
xs[i] = a[i];
}
sort(xs, xs + n);
LL res = 0;
for(int i = 0; i < n; i ++)
{
int t = lower_bound(xs, xs + n, a[i]) - xs + 1;
int q = query(t); //前面小于等于a[i]的数量
res += (LL)(i - q) * (t - 1 - q); //前面大于 a[i] * 后面小于a[i] 数量
add(t, 1);
}
cout << res << endl;
return 0;
}