1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include<iostream> #include<cstdio> #include<stack> #include<queue> #include<deque> #include<vector> #include<cstdlib> #include<string> #include<cstring> #include<algorithm> #include<ctime> #include<bitset> #include<set> #include<cmath> using namespace std;
#define rint register int #define Int64 long long #define max(x,y) (((x)>(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y)) #define clr(x,y) memset(x,y,sizeof(x)) #define sqar(x) (x)*(x) #define lowbit(x) (x&(-x)) #define swp(x,y) x^=y,y^=x,x^=y #define Maxn 100005 #define Mod 99999997
int N,ans; struct dbk{ int val; int pos;
bool operator <(const dbk &obj)const{ return val<obj.val; } }A[Maxn],B[Maxn]; int tmp[Maxn];
struct tree_array{ int v[Maxn];
void modify(int pos){ while(pos<=N){ v[pos]++; pos+=lowbit(pos); } }
int query(int pos){ int res=0; while(pos){ res+=v[pos]; res%=Mod; pos-=lowbit(pos); } return res; } }T;
void sol(){ for(int i=1;i<=N;i++){ cin>>A[i].val; A[i].pos=i; } for(int i=1;i<=N;i++){ cin>>B[i].val; B[i].pos=i; } sort(A+1,A+1+N); sort(B+1,B+1+N); for(int i=1;i<=N;i++){ tmp[A[i].pos]=B[i].pos; } for(int i=1;i<=N;i++){ T.modify(tmp[i]); ans+=(T.query(N)-T.query(tmp[i])); ans%=Mod;ans+=Mod;ans%=Mod; } }
int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif cin>>N; sol(); cout<<ans; return 0; }
|