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, 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(sortA[i] > sortB[i]) {
		puts("No");
		return 0;
	}
	
	for(rgi i = 1; i <= n - 1; ++i)	if(sortA[i + 1] <= sortB[i]) {
		puts("Yes");
		return 0;
	}
	//Exclusion
	
	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[cur];
			} 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(sortA[i] > sortB[i]) {
      |                 ^
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(sortA[i + 1] <= sortB[i]) {
      |                 ^
a.cc:48:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   48 |         for(rgi i = 1; i <= n; ++i)     posB[b[i]] = i;
      |                 ^
a.cc:51:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   51 |         for(rgi i = 1; i <= n; ++i) rankA[sortA[i]] = i;
      |                 ^
a.cc:54:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   54 |         for(rgi i = 1; i <= n; ++i) {
      |                 ^
a.cc:59:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   59 |         for(rgi i = 1; i <= n; ++i) {
      |                 ^
a.cc:66:25: error: 'cnt' was not declared in this scope; did you mean 'int'?
   66 |                         cnt++;
      |                         ^~~
      |                         int
a.cc:70:14: error: 'cnt' was not declared in this scope; did you mean 'int'?
   70 |         puts(cnt == 1 ? "No" : "Yes");
      |              ^~~
      |              int