|
- #include<iostream>
- #include<algorithm>
- #include<cstdio>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int N=100005,INF=99999997;
- long long int n,ans,t[N],d[N];
- struct node
- {
- long long int num,h;
- }a[N],b[N];
- void Merge(long long int l,long long int r)
- {
- if(l==r)return;
- long long int mid=l+((r-l)>>1);
- Merge(l,mid);
- Merge(mid+1,r);
- long long int i=l,j=mid+1,p=l;
- while(i<=mid && j<=r)
- {
- if(t[i]>t[j])
- {
- d[p++]=t[j++];
- ans+=mid-i+1;
- }
- else d[p++]=t[i++];
- }
- while(i<=mid)d[p++]=t[i++];
- while(j<=r)d[p++]=t[j++];
- FOR(i,l,r)t[i]=d[i];
- }
- inline bool cmp1(node x,node y){return x.h<y.h;}
- inline bool cmp2(node x,node y){return x.num<y.num;}
- int main()
- {
- //freopen("testdata.in","r",stdin);
- cin>>n;
- FOR(i,1,n){cin>>a[i].h;a[i].num=i;}
- FOR(i,1,n){cin>>b[i].h;b[i].num=i;}
- sort(a+1,a+n+1,cmp1);
- sort(b+1,b+n+1,cmp1);
- FOR(i,1,n){t[a[i].num]=b[i].num;}
- Merge(1,n);
- cout<<ans%INF<<endl;
- return 0;
- }
复制代码 |
|