Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;

  pair<int, int> BA[N];
  int A[N], B[N];
  int sortA[N];
  rep(i, N) cin >> BA[i].second;
  rep(i, N) cin >> BA[i].first;

  sort(all(BA, N));

  rep(i, N) sortA[i] = A[i] = BA[i].second;
  rep(i, N) B[i] = BA[i].first;

  sort(all(sortA, N));

  rep(i, N) {
    if (sortA[i] > B[i]) {
      cout << "No\n";
      return 0;
    }
  }
  // これで少なくともソートさえすればA<=Bを満たせると保証された

  rep(i, N) A[i] = BA[i].second;
  int count = 0;
  rep(i, N) {
    if (sortA[i] == A[i]) {
      cout << "Yes\n";
      return 0;
    }
    if (A[i] > B[i])
      ++count;
  }
  if (count >= N-2)
    cout << "No\n";
  else
    cout << "Yes\n";

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:7: error: 'i' was not declared in this scope
   23 |   rep(i, N) cin >> BA[i].second;
      |       ^
a.cc:14:29: note: in definition of macro 'rep'
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                             ^~~~~~~~~~~
a.cc:14:41: error: 'repi' was not declared in this scope
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                         ^~~~
a.cc:23:3: note: in expansion of macro 'rep'
   23 |   rep(i, N) cin >> BA[i].second;
      |   ^~~
a.cc:14:46: error: '_rep' was not declared in this scope
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                              ^~~~
a.cc:23:3: note: in expansion of macro 'rep'
   23 |   rep(i, N) cin >> BA[i].second;
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:23:3: note: in expansion of macro 'rep'
   23 |   rep(i, N) cin >> BA[i].second;
      |   ^~~
a.cc:14:18: error: '_overload3' was not declared in this scope
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                  ^~~~~~~~~~
a.cc:23:3: note: in expansion of macro 'rep'
   23 |   rep(i, N) cin >> BA[i].second;
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:24:3: note: in expansion of macro 'rep'
   24 |   rep(i, N) cin >> BA[i].first;
      |   ^~~
a.cc:26:8: error: 'all' was not declared in this scope; did you mean 'atoll'?
   26 |   sort(all(BA, N));
      |        ^~~
      |        atoll
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:28:3: note: in expansion of macro 'rep'
   28 |   rep(i, N) sortA[i] = A[i] = BA[i].second;
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:29:3: note: in expansion of macro 'rep'
   29 |   rep(i, N) B[i] = BA[i].first;
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:33:3: note: in expansion of macro 'rep'
   33 |   rep(i, N) {
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:41:3: note: in expansion of macro 'rep'
   41 |   rep(i, N) A[i] = BA[i].second;
      |   ^~~
a.cc:14:51: error: expected primary-expression before ')' token
   14 | #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
      |                                                   ^
a.cc:43:3: note: in expansion of macro 'rep'
   43 |   rep(i, N) {
      |   ^~~