#line 1 "main.cpp" #include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template bool chmin(T &a, const U &b){ return (a > b ? a = b, true : false); } template bool chmax(T &a, const U &b){ return (a < b ? a = b, true : false); } template void fill_array(T (&a)[N], const U &v){ std::fill((U*)a, (U*)(a + N), v); } template auto make_vector(const std::array &a, T value = T()){ static_assert(I >= 1); static_assert(N >= 1); if constexpr (I == 1){ return std::vector(a[N - I], value); }else{ return std::vector(a[N - I], make_vector(a, value)); } } template std::ostream& operator<<(std::ostream &s, const std::vector &a){ for(auto it = a.begin(); it != a.end(); ++it){ if(it != a.begin()) s << " "; s << *it; } return s; } template std::istream& operator>>(std::istream &s, std::vector &a){ for(auto &x : a) s >> x; return s; } std::string YesNo(bool value){return value ? "Yes" : "No";} std::string YESNO(bool value){return value ? "YES" : "NO";} std::string yesno(bool value){return value ? "yes" : "no";} template void putl(const T &value){ std::cout << value << "\n"; } template void putl(const Head head, const Tail &... tail){ std::cout << head << " "; putl(tail ...); } #line 4 "/home/haar/Downloads/kyopro-lib/Mylib/Utils/compressor.cpp" namespace haar_lib { template class compressor { std::vector data_; template friend class compressor_builder; public: int get_index(const T &val) const { return std::lower_bound(data_.begin(), data_.end(), val) - data_.begin(); } auto& compress(std::vector &vals) const { for(auto &x : vals) x = get_index(x); return *this; } auto& compress(T &val) const { val = get_index(val); return *this; } template auto& compress(U &val, Args &... args) const { compress(val); return compress(args ...); } auto& decompress(std::vector &vals) const { for(auto &x : vals) x = data_[x]; return *this; } auto& decompress(T &val) const { val = data_[val]; return *this; } template auto& decompress(U &val, Args &... args) const { decompress(val); return decompress(args ...); } int size() const {return data_.size();} T operator[](int index) const {return data_[index];} }; template class compressor_builder { std::vector data_; public: auto& add(const T &val){ data_.push_back(val); return *this; } auto& add(const std::vector &vals){ data_.insert(data_.end(), vals.begin(), vals.end()); return *this; } template auto& add(const U &val, const Args &... args){ add(val); return add(args ...); } auto build() const { compressor ret; ret.data_ = data_; std::sort(ret.data_.begin(), ret.data_.end()); ret.data_.erase(std::unique(ret.data_.begin(), ret.data_.end()), ret.data_.end()); return ret; } }; } #line 4 "/home/haar/Downloads/kyopro-lib/Mylib/DataStructure/FenwickTree/fenwick_tree_add.cpp" namespace haar_lib { template class fenwick_tree_add { public: using value_type = T; private: int size_; std::vector data_; public: fenwick_tree_add(){} fenwick_tree_add(int size): size_(size), data_(size + 1, 0){} void update(int i, value_type val){ assert(0 <= i and i < size_); i += 1; // 1-index while(i <= size_){ data_[i] = data_[i] + val; i += i & (-i); } } value_type fold(int i) const { // [0, i) assert(0 <= i and i <= size_); value_type ret = 0; while(i > 0){ ret = ret + data_[i]; i -= i & (-i); } return ret; } value_type fold(int l, int r) const { // [l, r) assert(0 <= l and l <= r and r <= size_); return fold(r) - fold(l); } value_type operator[](int x) const { return fold(x, x + 1); } }; } #line 67 "main.cpp" namespace haar_lib {} namespace solver { using namespace haar_lib; constexpr int m1000000007 = 1000000007; constexpr int m998244353 = 998244353; void init(){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); std::cerr << std::fixed << std::setprecision(12); std::cin.exceptions(std::ios_base::failbit); } void solve(){ int N; std::cin >> N; std::vector a(N), b(N); std::cin >> a >> b; compressor_builder().add(a, b).build().compress(a, b); int64_t ans = 0; std::sort(a.begin(), a.end()); fenwick_tree_add s(2 * N); for(int i = 0; i < N; ++i){ s.update(b[i], 1); ans += s.fold(a[i]); } std::cout << ans << "\n"; } } int main(){ solver::init(); while(true){ try{ solver::solve(); std::cout << std::flush; std::cerr << std::flush; }catch(const std::istream::failure &e){ break; }catch(...){ break; } } return 0; }