#include<iostream> #include<cstdio> #include<algorithm> #include<map> #include<cmath> using namespace std; #define mo 99999997 int n,ans; int a[100030],b[100030],aa[100030],bb[100030],t[100030],p[100030],q[100030]; map<int,int> m_a,m_b; int merge(int l,int r){ if (l==r) return 0; int mid=(l+r)>>1; int sum=(merge(l,mid)+merge(mid+1,r))%mo; int j=mid+1; for (int i=l;i<=mid;i++){ while (j<=r && q[i]>q[j]) j++; sum=(sum+j-mid-1)%mo; } int xb=l; j=mid+1; for (int i=l;i<=mid;i++){ while (j<=r && q[i]>q[j]){ t[xb]=q[j]; xb++; j++; } t[xb]=q[i]; xb++; } while (j<=r){ t[xb]=q[j]; xb++; j++; } for (int i=l;i<=r;i++) q[i]=t[i]; return sum%mo; } int main(){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]),aa[i]=a[i]; for (int i=1;i<=n;i++) scanf("%d",&b[i]),bb[i]=b[i]; sort(aa+1,aa+n+1); sort(bb+1,bb+n+1); for (int i=1;i<=n;i++) m_b[bb[i]]=i; for (int i=1;i<=n;i++) p[m_b[b[i]]]=i; for (int i=1;i<=n;i++) m_a[aa[i]]=i; for (int i=1;i<=n;i++) q[i]=p[m_a[a[i]]]; ans=merge(1,n); printf("%d\n",ans); return 0; }
|