#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/compress.hpp" #include #include #include template std::map compress(std::vector& v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); std::map rev; for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i; return rev; } #line 2 "main.cpp" #include #include #line 7 "main.cpp" using lint = long long; void solve() { int n; std::cin >> n; std::vector xs(n), ys(n); for (auto& x : xs) std::cin >> x; for (auto& y : ys) std::cin >> y; auto zs = xs; std::copy(ys.begin(), ys.end(), std::back_inserter(zs)); auto zrev = compress(zs); for (auto& x : xs) x = zrev[x]; for (auto& y : ys) y = zrev[y]; int m = zs.size(); std::sort(xs.begin(), xs.end()); lint ans = 0; atcoder::fenwick_tree bit(m); for (int i = 0; i < n; ++i) { bit.add(ys[i], 1); ans += bit.sum(0, xs[i]); } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }