Language: C++

#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

const int MAX_N = 200010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}
int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    set<int> st;
    rep(i, N) {
        cin >> A[i];
        st.insert(A[i]);
    }
    rep(i, N) {
        cin >> B[i];
        st.insert(B[i]);
    }
    if (N == 2 && (A[0] > B[0] || A[1] > B[1]) {
        cout << "No" << endl;
        return 0;
    }
    vector<int> f(0);
    map<int, int> g;
    for (auto i = st.begin(); i != st.end(); i++) {
        f.push_back(*i);
        g[*i] = f.size() - 1;
    }
    /*
    rep(i, f.size()) cout << f[i];
    cout << endl;
    for (auto i = g.begin(); i != g.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }
    */
    rep(i, N) {
        A[i] = g[A[i]];
        B[i] = g[B[i]];
    }
    /*
    rep(i, N) cout << A[i];
    cout << endl;
    rep(i, N) cout << B[i];
    cout << endl;
    */
    int m = f.size();
    init(m);
    vector<vector<int>> C(0);
    rep(i, N) {
        C.push_back({A[i], -1});
        C.push_back({B[i], 1});
    }
    sort(C.begin(), C.end());
    //rep(i, C.size()) cout << C[i][0] << C[i][1] << endl;
    int s = 0, x = -1;
    rep(i, C.size()) {
        if (x == -1) x = C[i][0];
        s += C[i][1];
        if (s > 0) {
            cout << "No" << endl;
            return 0;
        }
        unite(x, C[i][0]);
        if (s == 0) x = -1;
    }
    //rep(i, m) cout << i << find(i) << endl;
    rep(i, N) {
        if (same(A[i], B[i])) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:54:47: error: expected ';' before '{' token
   54 |     if (N == 2 && (A[0] > B[0] || A[1] > B[1]) {
      |                                               ^~
      |                                               ;
a.cc:58:18: error: expected initializer before '(' token
   58 |     vector<int> f(0);
      |                  ^
a.cc:58:18: error: expected ')' before '(' token
   58 |     vector<int> f(0);
      |                  ^
      |                  )
a.cc:54:8: note: to match this '('
   54 |     if (N == 2 && (A[0] > B[0] || A[1] > B[1]) {
      |        ^
a.cc:58:20: error: could not convert 'f' from 'std::vector<int>' to 'bool'
   58 |     vector<int> f(0);
      |                    ^
      |                    |
      |                    std::vector<int>
a.cc:61:9: error: 'f' was not declared in this scope
   61 |         f.push_back(*i);
      |         ^
a.cc:81:13: error: 'f' was not declared in this scope
   81 |     int m = f.size();
      |             ^