Language: C++

#include <bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
const ll INF = LLONG_MAX / 10;

template <typename M> struct SegmentTree {
    using T = typename M::T;
    int n;
    vector<T> dat;
    SegmentTree() {}
    SegmentTree(int n_) { init(n_); }
    SegmentTree(const vector<T> &v) { build(v); }
    void init(int n_) {
        n = 1;
        while(n < n_)
            n <<= 1;
        dat.assign(n << 1, M::ti());
    }
    void build(const vector<T> &v) {
        int n_ = v.size();
        init(n_);
        for(int i = 0; i < n_; i++)
            dat[n + i] = v[i];
        for(int i = n - 1; i; i--)
            dat[i] = M::f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
    void set_val(int k, T x) {
        dat[k += n] = x;
        while(k >>= 1)
            dat[k] = M::f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
    //[a,b)
    T query(int a, int b, int k = 1, int l = 0, int r = -1) {
        if(r < 0)
            r = n;
        if(r <= a || b <= l)
            return M::ti();
        if(a <= l && r <= b)
            return dat[k];
        T vl = query(a, b, k * 2, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 1, (l + r) / 2, r);
        return M::f(vl, vr);
    }
    T operator[](const int &k) const { return dat[k + n]; }
};

struct RandQ {
    using T = bool;
    static T ti() { return true; }
    static T f(const T &l, const T &r) { return l & r; }
};
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    pair<ll, ll> A[N], B[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A, A + N);
    for(int i = 0; i < N; i++) {
        cin >> B[i].first;
        B[i].second = i;
    }
    sort(B, B + N);
    int iA[N], iB[N];
    for(int i = 0; i < N; i++) {
        iA[A[i].second] = i;
        iB[B[i].second] = i;
    }
    bool isok = true;
    for(int i = 0; i < N; i++) {
        isok &= A[i].first <= B[i].first;
    }
    if(!isok) {
        cout << "No" << endl;
        return 0;
    }
    SegmentTree<RandQ> seg(N - 1);
    for(int i = 0; i < N - 1; i++) {
        seg.set_val(i, A[i + 1].first <= B[i].first);
    }
    isok = false;
    for(int i = 0; i < N; i++) {
        if(iA[i] == iB[i]) {
            isok = true;
            break;
        }
        /*
        debug(iA[i]);
        debug(iB[i]);
        */
        if(iA[i] < iB[i]) {
            isok |=
                A[iA[i]].first <= B[iB[i]].first && seg2.query(iA[i], iB[i]);
        } else {
            isok |= A[iA[i]].first <= B[iB[i]].first;
        }
    }
    cout << (isok ? "Yes" : "No") << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:103:53: error: 'seg2' was not declared in this scope; did you mean 'seg'?
  103 |                 A[iA[i]].first <= B[iB[i]].first && seg2.query(iA[i], iB[i]);
      |                                                     ^~~~
      |                                                     seg