Language: C++

#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multi int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T a){while(n--)cin >> *a, ++a;}
template<typename T1, typename T2> void read(int n, T1 a, T2 b){while(n--)cin >> *a >> *b, ++a, ++b;}
template<typename T> void write(int n, T a){while(n--)cout << *a << " \n"[n==0], ++a;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
string res[2]{"No", "Yes"};
const int inf = 1<<30;
int n;
int a[maxn], b[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	read(n, a);
	read(n, b);
	int cnt = 0;
	map<int, int> ma;
	{
		vector<int> ca(a,a+n), cb(b,b+n);
		sort(ca.begin(), ca.end());
		sort(cb.begin(), cb.end());
		for(int i = 0;i < n;++i)if(ca[i] > cb[i]){
			rout("No");
		}
		for(int j : ca)ma[j] = inf;
		int i = n-1, j = n;
		for(;j > 0;--i){
			while(j > 0 and ca[i] <= cb[j-1])--j;
		}
		j += (n-1 - (j+(n-1-i)));
		j = min(j, n-1);
		for(int c = 0;c < i;++c)ma[ca[c]] = min(ma[ca[c]], cb[j]);
		for(;i < n;++i, j = min(j, n-1))ma[ca[i]] = min(ma[ca[i]], cb[j]), ++j;
		rep0(i, n)if(b[i] <= ma[a[i]] and a[i] <= b[i])rout("Yes");
	map<int,int> cnt;
		rep0(i, n){
			a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
			++cnt[a[i]];
		}
	}
	for(int i = 0;i < n;++i){
		while(a[i] != i){
			swap(a[i], a[a[i]]), ++cnt;
		}
	}
	rout(res[cnt <= n-1]);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:71: error: no match for 'operator-' (operand types are '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' and 'std::vector<int>')
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
      |                                           |                            |
      |                                           |                            std::vector<int>
      |                                           __gnu_cxx::__normal_iterator<int*, std::vector<int> >
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/extc++.h:32,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:1148:7: note: candidate: '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-(difference_type) const [with _Iterator = int*; _Container = std::vector<int>; difference_type = long int]'
 1148 |       operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1148:33: note:   no known conversion for argument 1 from 'std::vector<int>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'}
 1148 |       operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
      |                 ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  618 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::reverse_iterator<_Iterator>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1790 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::move_iterator<_IteratorL>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/complex:370:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const complex<_Tp>&)'
  370 |     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:370:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::complex<_Tp>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/complex:379:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const _Tp&)'
  379 |     operator-(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:379:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::complex<_Tp>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/complex:388:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const _Tp&, const complex<_Tp>&)'
  388 |     operator-(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:388:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   'std::vector<int>' is not derived from 'const std::complex<_Tp>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/complex:465:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&)'
  465 |     operator-(const complex<_Tp>& __x)
      |     ^~~~~~~~
/usr/include/c++/14/complex:465:5: note:   candidate expects 1 argument, 2 provided
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   'std::vector<int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/bits/valarray_after.h:406:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__minus, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__minus, typename _Dom1::value_type>::result_type> std::operator-(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  406 |     _DEFINE_EXPR_BINARY_OPERATOR(-, struct std::__minus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:406:5: note:   template argument deduction/substitution failed:
a.cc:59:72: note:   'std::vector<int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   59 |                         a[i] = lower_bound(ca.begin(), ca.end(), a[i])-ca+cnt[a[i]];
      |                                                                        ^~
/usr/include/c++/14/valarray:1197:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__minus, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__minus, _Tp>::result_type> std::operator-(const val