Language: C++

#include <bits/stdc++.h>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

const int N = 2e5 + 10;

int n, tot, cnt, num[N], nxt[N], vis[N];
int a[N], sortA[N], rankA[N];
int b[N], sortB[N], posB[N];

il int read() {
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main() {
	n = read();
	for(rgi i = 1; i <= n; ++i)	a[i] = num[++tot] = read();
	for(rgi i = 1; i <= n; ++i)	b[i] = num[++tot] = read();
	
	std::sort(num + 1, num + tot + 1);
	tot = std::unique(num + 1, num + tot + 1) - (num + 1);
	for(rgi i = 1; i <= n; ++i)	a[i] = std::lower_bound(num + 1, num + tot + 1, a[i]) - (num + 1) + 1;
	for(rgi i = 1; i <= n; ++i)	b[i] = std::lower_bound(num + 1, num + tot + 1, b[i]) - (num + 1) + 1;
	//Discrete
	
	for(rgi i = 1; i <= n; ++i)	sortA[i] = a[i];
	for(rgi i = 1; i <= n; ++i)	sortB[i] = b[i];
	std::sort(sortA + 1, sortA + n + 1);
	std::sort(sortB + 1, sortB + n + 1);
	//Smallest Permutation
	
	for(rgi i = 1; i <= n; ++i)	if(tmpA[i] > tmpB[i]) {
		puts("No");
		return 0;
	}
	
	for(rgi i = 1; i <= n - 1; ++i)	if(tmpA[i] <= tmpB[i + 1]) {
		puts("Yes");
		return 0;
	}
	
	for(rgi i = 1; i <= n; ++i)	posB[b[i]] = i;
	//pos in b[]
	
	for(rgi i = 1; i <= n; ++i) rankA[sortA[i]] = i;
	//rank in a[]
	
	for(rgi i = 1; i <= n; ++i) {
		nxt[i] = posB[sortB[rankA[a[i]]]];
	}
	//Add edges
	
	for(rgi i = 1; i <= n; ++i) {
		if(!vis[i]) {
			int cur = i;
			
			do {
				vis[cur] = 1;
				cur = nxt[i];
			} while(!vis[cur]); 
			
			cnt++;
		}
	}
	
	puts(cnt == 1 ? "No" : "Yes");
	
	return 0;
}


Compiler output:
a.cc: In function 'int read()':
a.cc:14:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 |         rgi x = 0, f = 0, ch;
      |             ^
a.cc:14:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 |         rgi x = 0, f = 0, ch;
      |                    ^
a.cc:14:27: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   14 |         rgi x = 0, f = 0, ch;
      |                           ^~
a.cc: In function 'int main()':
a.cc:22:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   22 |         for(rgi i = 1; i <= n; ++i)     a[i] = num[++tot] = read();
      |                 ^
a.cc:23:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |         for(rgi i = 1; i <= n; ++i)     b[i] = num[++tot] = read();
      |                 ^
a.cc:27:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |         for(rgi i = 1; i <= n; ++i)     a[i] = std::lower_bound(num + 1, num + tot + 1, a[i]) - (num + 1) + 1;
      |                 ^
a.cc:28:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   28 |         for(rgi i = 1; i <= n; ++i)     b[i] = std::lower_bound(num + 1, num + tot + 1, b[i]) - (num + 1) + 1;
      |                 ^
a.cc:31:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   31 |         for(rgi i = 1; i <= n; ++i)     sortA[i] = a[i];
      |                 ^
a.cc:32:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   32 |         for(rgi i = 1; i <= n; ++i)     sortB[i] = b[i];
      |                 ^
a.cc:37:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         for(rgi i = 1; i <= n; ++i)     if(tmpA[i] > tmpB[i]) {
      |                 ^
a.cc:37:44: error: 'tmpA' was not declared in this scope; did you mean 'tm'?
   37 |         for(rgi i = 1; i <= n; ++i)     if(tmpA[i] > tmpB[i]) {
      |                                            ^~~~
      |                                            tm
a.cc:37:54: error: 'tmpB' was not declared in this scope; did you mean 'tm'?
   37 |         for(rgi i = 1; i <= n; ++i)     if(tmpA[i] > tmpB[i]) {
      |                                                      ^~~~
      |                                                      tm
a.cc:42:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   42 |         for(rgi i = 1; i <= n - 1; ++i) if(tmpA[i] <= tmpB[i + 1]) {
      |                 ^
a.cc:42:44: error: 'tmpA' was not declared in this scope; did you mean 'tm'?
   42 |         for(rgi i = 1; i <= n - 1; ++i) if(tmpA[i] <= tmpB[i + 1]) {
      |                                            ^~~~
      |                                            tm
a.cc:42:55: error: 'tmpB' was not declared in this scope; did you mean 'tm'?
   42 |         for(rgi i = 1; i <= n - 1; ++i) if(tmpA[i] <= tmpB[i + 1]) {
      |                                                       ^~~~
      |                                                       tm
a.cc:47:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         for(rgi i = 1; i <= n; ++i)     posB[b[i]] = i;
      |                 ^
a.cc:50:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |         for(rgi i = 1; i <= n; ++i) rankA[sortA[i]] = i;
      |                 ^
a.cc:53:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   53 |         for(rgi i = 1; i <= n; ++i) {
      |                 ^
a.cc:58:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   58 |         for(rgi i = 1; i <= n; ++i) {
      |                 ^