#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
int n, ans;
int c[10000005];
struct node {
int x, y;
} a[10000005];
int lowbit(int x) {
return x & (-x);
}
void upd(int x, int y) {
while (x <= n) c[x] += y, x += lowbit(x);
}
int sum(int x) {
int t = 0;
while (x > 0) t += c[x], x -= lowbit(x);
return t;
}
bool cmp(node x, node y) {
return x.x > y.x;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x;
a[i].y = i;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
upd(a[i].y, 1);
ans += sum(a[i].y - 1);
}
cout << ans << endl;
return 0;
}
各位大佬帮忙看一下