Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename Abelian>
struct BIT {
  BIT(int n, const Abelian &UNITY = 0) : n(n), UNITY(UNITY), dat(n, UNITY) {}

  void add(int idx, const Abelian &value) {
    while (idx < n) {
      dat[idx] += value;
      idx |= idx + 1;
    }
  }

  Abelian sum(int idx) {
    Abelian res = UNITY;
    while (idx >= 0) {
      res += dat[idx];
      idx = (idx & (idx + 1)) - 1;
    }
    return res;
  }

  Abelian sum(int left, int right) { return sum(right) - sum(left - 1); }

  Abelian operator[](const int idx) { return sum(idx, idx); }

  int lower_bound(Abelian value) {
    if (value <= UNITY) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      if (res + mask - 1 < n && dat[res + mask - 1] < value) {
        value -= dat[res + mask - 1];
        res += mask;
      }
    }
    return res;
  }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat;
};

template <typename T>
long long inversion_number(const vector<T> &a) {
  int n = a.size();
  vector<T> cp(a);
  sort(ALL(cp));
  cp.erase(unique(ALL(cp)), cp.end());
  BIT<int> bit(cp.size());
  long long res = 0;
  REP(i, n) {
    int idx = lower_bound(ALL(cp), a[i]) - cp.begin();
    res += i - bit.sum(idx);
    bit.add(idx, 1);
  }
  return res;
}

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  vector<int> cop_a(a), cop_b(b);
  sort(ALL(cop_a));
  sort(ALL(cop_b));
  REP(i, n) {
    if (cop_a[i] > cop_b[i]) {
      cout << "No\n";
      return 0;
    }
  }
  map<int, int> group;
  map<int, set<int> > elem;
  int l = 0;
  FOR(i, 1, n) {
    if (cop_a[i] > cop_b[l]) {
      int sz = group.size();
      FOR(j, l, i) {
        group[cop_a[j]] = sz;
        elem[sz].emplace(cop_b[j]);
      }
      l = i;
    }
  }
  int sz = group.size();
  FOR(j, l, n) {
    group[cop_a[j]] = sz;
    elem[sz].emplace(cop_b[j]);
  }
  REP(i, n) {
    if (elem[group[a[i]]].count(b[i]) == 1) {
      cout << "Yes\n";
      return 0;
    }
  }
  vector<pair<int, int> > ba(n);
  REP(i, n) ba[i] = {b[i], a[i]};
  sort(ALL(ba));
  vector<int> atara_a(n);
  REP(i, n) atara_a[i] = ba[i].second;
  if (inversion_number(atara_a) == n - 1) {
    cout << "No\n";
    return 0;
  }
  vector<int> cop_b(b);
  sort(ALL(b));
  b.erase(unique(ALL(b)), b.end());
  if (b.size() == n) {
    cout << "No\n";
    return 0;
  }
  assert(false);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:152:15: error: redeclaration of 'std::vector<int, std::allocator<int> > cop_b'
  152 |   vector<int> cop_b(b);
      |               ^~~~~
a.cc:110:25: note: 'std::vector<int, std::allocator<int> > cop_b' previously declared here
  110 |   vector<int> cop_a(a), cop_b(b);
      |                         ^~~~~