【代码】
归并排序模板
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
#define f(i,n) for(int i=1;i<=(n);i++)
#define ll long long
#define INF 1<<30
#define N 100010
#define c 99999997
using namespace std;
int z[N];
int ans;
int n;
int temp[N];
void merge(int l,int m,int r)
{
int i=l,j=m+1,k=l;
while(i<=m&&j<=r)
{
if(z[i]>z[j])
{
temp[k++]=z[j++];
ans=(ans+m-i+1)%c;
}
else temp[k++]=z[i++];
}
while(i<=m)temp[k++]=z[i++];
while(j<=r)temp[k++]=z[j++];
for(int v=l;v<=r;v++)z[v]=temp[v];
}
void merge_sort(int l,int r)
{
if(l>=r)return;
int mid=(l+r)>>1;
merge_sort(l,mid);
merge_sort(mid+1,r);
merge(l,mid,r);
}
int main()
{
scanf("%d",&n);
f(i,n)scanf("%d",&z[i]);
merge_sort(1,n);
printf("%d",ans);
}