You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
// 暴力大法好!
|
|
|
|
|
// 过掉4/10个数据
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 2000010;
|
|
|
|
|
typedef long long LL;
|
|
|
|
|
|
|
|
|
|
int a[N];
|
|
|
|
|
// ll[i]表示i的左边比第i个数小的数的个数
|
|
|
|
|
// rl[i]表示i的右边比第i个数小的数的个数
|
|
|
|
|
// lg[i]表示i的左边比第i个数大的数的个数
|
|
|
|
|
// rg[i]表示i的右边比第i个数大的数的个数
|
|
|
|
|
int ll[N], rl[N], lg[N], rg[N];
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
for (int i = 1; i <= n; i++) scanf("%d", &a[i]); // 纵坐标
|
|
|
|
|
|
|
|
|
|
// 双重循环,暴力求每个坐标左边比自己小,比自己大的个数
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
for (int j = 1; j < i; j++) {
|
|
|
|
|
// a[]保存的是1 ~ n的一个排列,不可能相等(题意)
|
|
|
|
|
if (a[j] < a[i])
|
|
|
|
|
ll[i]++;
|
|
|
|
|
else
|
|
|
|
|
lg[i]++;
|
|
|
|
|
}
|
|
|
|
|
// 双重循环,暴力求每个坐标右边比自己小的,比自己大的个数
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
for (int j = i + 1; j <= n; j++) {
|
|
|
|
|
if (a[j] < a[i])
|
|
|
|
|
rl[i]++;
|
|
|
|
|
else
|
|
|
|
|
rg[i]++;
|
|
|
|
|
}
|
|
|
|
|
// 利用乘法原理,计算左侧比自己小,右侧比自己小的数量乘积(或比自己大)
|
|
|
|
|
LL resV = 0, resA = 0;
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
resV += (LL)lg[i] * rg[i];
|
|
|
|
|
resA += (LL)ll[i] * rl[i];
|
|
|
|
|
}
|
|
|
|
|
printf("%lld %lld\n", resV, resA);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|