文件目录

#include <iostream>
#include <vector>
using namespace std;
int n, a[100050] = {};
long long ans = 0;
void msort(int left, int right)
{
    if (left == right)
        return;
    int mid = (left + right) / 2;
    msort(left, mid);
    msort(mid + 1, right);
    // 合并
    vector<int> t;
    int i = left, j = mid + 1;
    while (i <= mid && j <= right)
    {
        if (a[i] > a[j])
        {
            t.push_back(a[j++]);
            ans += mid - i + 1;
        }
        else
            t.push_back(a[i++]);
    }
    while (i <= mid)
        t.push_back(a[i++]);
    while (j <= right)
        t.push_back(a[j++]);
    for (int i = left, j = 0; i <= right; j++, i++)
    {
        a[i] = t[j];
    }
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    msort(0, n - 1);
    cout << ans;
    return 0;
}