Language: C++

using namespace std;

struct SortItem
{
  uint64_t a, b;
  SortItem(uint64_t a = -1, uint64_t b = -1) : a(a), b(b) {}

  bool operator<(const SortItem &item) const {
    return (b == item.b) ? a < item.a : b < item.b;
  }
};

struct VectorItem
{
  uint64_t v, i;
  VectorItem(uint64_t v = -1, uint64_t i = -1) : v(v), i(i) {}

  bool operator<(const VectorItem &item) const {
    return v < item.v;
  }
};

uint64_t count_cycles(uint64_t N, const vector<VectorItem> &A)
{
  uint64_t count = 0;
  vector<bool> checked(N, false);

  for (uint64_t n = 0; n < N; ++n) {
    if (checked[n]) { continue; }

    uint64_t start = n, index = A[n].i;
    checked[start] = true;
    while (index != start) {
      checked[index] = true;

      index = A[index].i;
      if (checked[index]) { break; }
    }

    ++count;
  }

  return count;
}

int main()
{
  uint64_t N;
  cin >> N;

  vector<uint64_t> A(N), B(N);
  for (uint64_t n = 0; n < N; ++n) { cin >> A[n]; }
  for (uint64_t n = 0; n < N; ++n) { cin >> B[n]; }

  vector<SortItem> vec(N);
  for (uint64_t n = 0; n < N; ++n) { vec[n] = SortItem(A[n], B[n]); }
  sort(vec.begin(), vec.end());

  vector<VectorItem> C(N), D(N);
  for (uint64_t n = 0; n < N; ++n) { C[n].v = vec[n].a; C[n].i = n; }
  for (uint64_t n = 0; n < N; ++n) { D[n].v = vec[n].b; D[n].i = n; }
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());

  bool flag = true;
  for (uint64_t n = 0; n < N; ++n) {
    flag &= C[n].v <= D[n].v;
  }

  if (count_cycles(N, C) == 1) {
    bool flag2 = false;
    for (uint64_t n = 0; n < N - 1; ++n) {
      flag2 |= D[n].v >= C[n + 1].v;
    }
    flag &= flag2;
  }

  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}

Compiler output:
a.cc:5:3: error: 'uint64_t' does not name a type
    5 |   uint64_t a, b;
      |   ^~~~~~~~
a.cc:1:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
  +++ |+#include <cstdint>
    1 | using namespace std;
a.cc:6:20: error: expected ')' before 'a'
    6 |   SortItem(uint64_t a = -1, uint64_t b = -1) : a(a), b(b) {}
      |           ~        ^~
      |                    )
a.cc: In member function 'bool SortItem::operator<(const SortItem&) const':
a.cc:9:13: error: 'b' was not declared in this scope
    9 |     return (b == item.b) ? a < item.a : b < item.b;
      |             ^
a.cc:9:23: error: 'const struct SortItem' has no member named 'b'
    9 |     return (b == item.b) ? a < item.a : b < item.b;
      |                       ^
a.cc:9:28: error: 'a' was not declared in this scope
    9 |     return (b == item.b) ? a < item.a : b < item.b;
      |                            ^
a.cc:9:37: error: 'const struct SortItem' has no member named 'a'
    9 |     return (b == item.b) ? a < item.a : b < item.b;
      |                                     ^
a.cc:9:50: error: 'const struct SortItem' has no member named 'b'
    9 |     return (b == item.b) ? a < item.a : b < item.b;
      |                                                  ^
a.cc: At global scope:
a.cc:15:3: error: 'uint64_t' does not name a type
   15 |   uint64_t v, i;
      |   ^~~~~~~~
a.cc:15:3: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:16:22: error: expected ')' before 'v'
   16 |   VectorItem(uint64_t v = -1, uint64_t i = -1) : v(v), i(i) {}
      |             ~        ^~
      |                      )
a.cc: In member function 'bool VectorItem::operator<(const VectorItem&) const':
a.cc:19:12: error: 'v' was not declared in this scope
   19 |     return v < item.v;
      |            ^
a.cc:19:21: error: 'const struct VectorItem' has no member named 'v'
   19 |     return v < item.v;
      |                     ^
a.cc: At global scope:
a.cc:23:1: error: 'uint64_t' does not name a type
   23 | uint64_t count_cycles(uint64_t N, const vector<VectorItem> &A)
      | ^~~~~~~~
a.cc:23:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In function 'int main()':
a.cc:48:3: error: 'uint64_t' was not declared in this scope
   48 |   uint64_t N;
      |   ^~~~~~~~
a.cc:48:3: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:49:3: error: 'cin' was not declared in this scope
   49 |   cin >> N;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:49:10: error: 'N' was not declared in this scope
   49 |   cin >> N;
      |          ^
a.cc:51:3: error: 'vector' was not declared in this scope
   51 |   vector<uint64_t> A(N), B(N);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:51:20: error: 'A' was not declared in this scope
   51 |   vector<uint64_t> A(N), B(N);
      |                    ^
a.cc:51:26: error: 'B' was not declared in this scope
   51 |   vector<uint64_t> A(N), B(N);
      |                          ^
a.cc:52:16: error: expected ';' before 'n'
   52 |   for (uint64_t n = 0; n < N; ++n) { cin >> A[n]; }
      |                ^~
      |                ;
a.cc:52:24: error: 'n' was not declared in this scope
   52 |   for (uint64_t n = 0; n < N; ++n) { cin >> A[n]; }
      |                        ^
a.cc:53:16: error: expected ';' before 'n'
   53 |   for (uint64_t n = 0; n < N; ++n) { cin >> B[n]; }
      |                ^~
      |                ;
a.cc:53:24: error: 'n' was not declared in this scope
   53 |   for (uint64_t n = 0; n < N; ++n) { cin >> B[n]; }
      |                        ^
a.cc:55:18: error: expected primary-expression before '>' token
   55 |   vector<SortItem> vec(N);
      |                  ^
a.cc:55:20: error: 'vec' was not declared in this scope
   55 |   vector<SortItem> vec(N);
      |                    ^~~
a.cc:56:16: error: expected ';' before 'n'
   56 |   for (uint64_t n = 0; n < N; ++n) { vec[n] = SortItem(A[n], B[n]); }
      |                ^~
      |                ;
a.cc:56:24: error: 'n' was not declared in this scope
   56 |   for (uint64_t n = 0; n < N; ++n) { vec[n] = SortItem(A[n], B[n]); }
      |                        ^
a.cc:57:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   57 |   sort(vec.begin(), vec.end());
      |   ^~~~
      |   short
a.cc:59:20: error: expected primary-expression before '>' token
   59 |   vector<VectorItem> C(N), D(N);
      |                    ^
a.cc:59:22: error: 'C' was not declared in this scope
   59 |   vector<VectorItem> C(N), D(N);
      |                      ^
a.cc:59:28: error: 'D' was not declared in this scope
   59 |   vector<VectorItem> C(N), D(N);
      |                            ^
a.cc:60:16: error: expected ';' before 'n'
   60 |   for (uint64_t n = 0; n < N; ++n) { C[n].v = vec[n].a; C[n].i = n; }
      |                ^~
      |                ;
a.cc:60:24: error: 'n' was not declared in this scope
   60 |   for (uint64_t n = 0; n < N; ++n) { C[n].v = vec[n].a; C[n].i = n; }
      |                        ^
a.cc:61:16: error: expected ';' before 'n'
   61 |   for (uint64_t n = 0; n < N; ++n) { D[n].v = vec[n].b; D[n].i = n; }
      |                ^~
      |                ;
a.cc:61:24: error: 'n' was not declared in this scope
   61 |   for (uint64_t n = 0; n < N; ++n) { D[n].v = vec[n].b; D[n].i = n; }
      |                        ^
a.cc:66:16: error: expected ';' before 'n'
   66 |   for (uint64_t n = 0; n < N; ++n) {
      |                ^~
      |                ;
a.cc:66:24: error: 'n' was not declared in this scope
   66 |   for (uint64_t n = 0; n < N; ++n) {
      |                        ^
a.cc:70:7: error: 'count_cycles' was not declared in this scope
   70 |   if (count_cycles(N, C) == 1) {
      |       ^~~~~~~~~~~~
a.cc:72:18: error: expected ';' before 'n'
   72 |     for (uint64_t n = 0; n < N - 1; ++n) {
      |                  ^~
      |                  ;
a.cc:72:26: error: 'n' was not declared in this scope
   72 |     for (uint64_t n = 0; n < N - 1; ++n) {
      |                          ^
a.cc:78:3: error: 'cout' was not declared in this scope
   78 |   cout << (flag ? "Yes" : "No") << endl;
      |   ^~~~
a.cc:78:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:78:36: error: 'endl' was not declared in this scope
   78 |   cout << (flag ? "Yes" : "No") << endl;
      |                                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;