template<typename T> inlinevoidread(T &x){/* fast read */}
constint N = 1e5 + 9; constint MOD = 99999997;
int n, ans; int a[N], b[N], tmp[N];
// 离散化 inlinevoidlsh(int *t){ for (int i = 1; i <= n; ++i) tmp[i] = t[i]; sort(tmp+1, tmp+n+1); int tot = unique(tmp+1, tmp+n+1) - tmp; for (int i = 1; i <= n; ++i) t[i] = lower_bound(tmp+1, tmp+tot+1, t[i]) - tmp; }
// 树状数组,用于求逆序对 structBit_Tree { int tr[N]; #define lowbit(x) (x & -x) inlinevoidadd(int x, int k){ while (x <= n) tr[x] += k, x += lowbit(x); } inlineintquery(int x){ int re = 0; while (x) re += tr[x], x -= lowbit(x); return re; } } tr;
inlinevoidmain(){ read(n); for (int i = 1; i <= n; ++i) read(a[i]); for (int i = 1; i <= n; ++i) read(b[i]); // 离散化,同时也是得到每个数的排名 lsh(a), lsh(b); // 让 b 数列每个元素得到 a 中同一排名元素的坐标 for (int i = 1; i <= n; ++i) tmp[a[i]] = i; for (int i = 1; i <= n; ++i) b[i] = tmp[b[i]]; // 统计答案 for (int i = 1; i <= n; ++i) { // 每次加入一个数增加逆序对数:原个数 - 小于它的元素个数 ans = (ans + i - 1 - tr.query(b[i])) % MOD; tr.add(b[i], 1); } printf("%d\n", ans); }