1 #include <bits/stdc++.h> 2 using namespace std; 3 const int MAXN = 100000 + 1; 4 const int MOD = 99999997; 5 int n, F[MAXN], C[MAXN]; 6 struct node 7 { 8 int N, H; 9 }Match1[MAXN], Match2[MAXN]; 10 void Update(int x) 11 { 12 for (int i = x; i <= n; i += i&(-i)) 13 F[i]++; 14 } 15 int Query(int x) 16 { 17 int S = 0; 18 for (int i = x; i > 0; i -= i&(-i)) 19 S += F[i]; 20 return S; 21 } 22 bool comp(node x, node y) 23 { 24 return x.H < y.H; 25 } 26 int main() 27 { 28 cin >> n; 29 for (int i = 1; i <= n; i++) 30 { 31 cin >> Match1[i].H; 32 Match1[i].N = i; 33 } 34 for (int i = 1; i <= n; i++) 35 { 36 cin >> Match2[i].H; 37 Match2[i].N = i; 38 } 39 sort(Match1 + 1, Match1 + (n+1), comp); 40 sort(Match2 + 1, Match2 + (n+1), comp); 41 for (int i = 1; i <= n; i++) 42 { 43 C[Match1[i].N] = Match2[i].N; 44 } 45 int Sum = 0; 46 for (int i = 1; i <= n; i++) 47 { 48 Update(C[i]); 49 Sum += i-Query(C[i]); 50 Sum %= MOD; 51 } 52 cout << Sum << endl; 53 return 0; 54 }