https://www.luogu.com.cn/problem/P1966
重置大小关系+树状数组求逆序对
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e8-3;
struct qr{
int l;
int r;
}a[100010],b[100010];
bool cmp(qr x,qr y)
{
if(x.l==y.l) return x.r<y.r;
return x.l<y.l;
}
int rk[100010];
int tree[100010];
int lowbit(int x) {return x&-x;}
void intree(int x,int n){for(;x<=n;x+=lowbit(x)) tree[x]++;}
int con(int x)
{
int ans=0;
for(;x>0;x-=lowbit(x)) ans+=tree[x];
return ans;
}
int main()
{
int n;
long long ans=0;
cin>>n;
for(int i=1;i<=n;i++) scanf("%d",&a[i].l);
for(int i=1;i<=n;i++) scanf("%d",&b[i].l);
for(int i=1;i<=n;i++) a[i].r=b[i].r=i;
sort(a+1,a+n+1,cmp);
sort(b+1,b+n+1,cmp);
for(int i=1;i<=n;i++) rk[b[i].r]=a[i].r;//按照a数组作为排序标准
for(int i=1;i<=n;i++)
{
intree(rk[i],n);
ans=(ans+i-con(rk[i]))%mod;
}
cout<<ans;
}