#ifndef ATCODER_INTERNAL_BITOP_HPP #define ATCODER_INTERNAL_BITOP_HPP 1 #ifdef _MSC_VER #include #include #endif namespace atcoder { namespace internal { int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } int bsf(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } } } #endif #ifndef ATCODER_SEGTREE_HPP #define ATCODER_SEGTREE_HPP 1 #include #include #include namespace atcoder { template struct segtree { public: segtree() : segtree(0) {} segtree(int n) : segtree(std::vector(n, e())) {} segtree(const std::vector& v) : _n(int(v.size())) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::vector(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } template int max_right(int l) { return max_right(l, [](S x) { return f(x); }); } template int max_right(int l, F f) { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template int min_left(int r) { return min_left(r, [](S x) { return f(x); }); } template int min_left(int r, F f) { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; } #endif #include using namespace std; using namespace atcoder; //using mint = modint998244353; //const int mod = 998244353; //using mint = modint1000000007; //const int mod = 1000000007; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int op(int a, int b) { return a + b; } int e() { return 0; } int op2(int a, int b) { return max(a, b); } int e2() { return -1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; vectora(n), b(n); rep(i, n)cin >> a[i], a[i]--; rep(i, n)cin >> b[i], b[i]--; vector>pos(n); vector>v(n); rep(i, n) { pos[a[i]].push_back(i); v[b[i]].push_back(i); } bool chk = true; segtreeseg(n); segtreeseg2(a); rep(i, n) { rep(j, v[i].size()) { bool subchk = false; //以下の数 int cnt0 = upper_bound(all(pos[i]), v[i][j]) - pos[i].begin(); if (0 != cnt0) { int idx = pos[i][cnt0 - 1]; auto get = seg.prod(idx, v[i][j] + 1); auto mx = seg2.prod(idx, v[i][j] + 1); //cout << get << endl; if (mx == i && !get)subchk = true; } //以上の数 int cnt1 = pos[i].end() - lower_bound(all(pos[i]), v[i][j]); if (0 != cnt1) { int idx = pos[i][pos[i].size() - cnt1]; auto get = seg.prod(v[i][j], idx + 1); auto mx = seg2.prod(v[i][j], idx + 1); //cout << get << endl; if (mx == i && !get)subchk = true; } if (!subchk)chk = false; } if (!chk)break; rep(j, v[i].size()) seg.set(v[i][j], 1); } if (chk)cout << "Yes" << endl; else cout << "No" << endl; } return 0; }