用树状数组求的
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn = 2000100;
int n, a[maxn];
ll bit[maxn];
int lowbit(int x) { return x & -x; }
ll query(int x) {
ll res = 0;
while (x > 0) {
res += bit[x];
x -= lowbit(x);
}
return res;
}
void add(int pos, int x) {
while (pos <= n) {
bit[pos] += x;
pos += lowbit(pos);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += (query(n) - query(a[i]));
add(a[i], 1);
}
printf("%lld\n", ans);
return 0;
}