不多说了,代码含注释
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
//a[i]表示1 ~ i-1有多少个比b[i]小的
//1 ~ i-1 > b[i] = i - 1 - a[i]
//i+1 ~ n < b[i] = b[i] - 1 - a[i]
//i+1 ~ n > b[i] = n - b[i] - (i - 1 - a[i]) = n - i + 1 + a[i] - b[i]
int n, /* a[N], b[N],*/ c[N];
void add(int x) {
for (; x <= n; x += x & -x) c[x]++;
}
int get(int x) {
int s = 0;
for (; x; x -= x & -x) s += c[x];
return s;
}
int main() {
cin >> n;
/* for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
a[i] = get(b[i] - 1);
add(b[i]);
}
LL s1 = 0, s2 = 0;
for (int i = 2; i < n; i++) {
s1 += 1ll * (i - 1 - a[i]) * (n - i + 1 + a[i] - b[i]);
s2 += 1ll * a[i] * (b[i] - 1 - a[i]);
}*/
LL s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++) {
int b; scanf("%d", &b);
int a = get(b - 1);
add(b);
s1 += 1ll * (i - 1 - a) * (n - i + 1 + a - b);
s2 += 1ll * a * (b - 1 - a);
}
cout << s1 << " " << s2 << endl;
return 0;
}