#include using namespace std; template struct sparse_table{ vector> ST; sparse_table(vector &A){ int N = A.size(); int LOG = 32 - __builtin_clz(N); ST = vector>(LOG, vector(N)); for (int i = 0; i < N; i++){ ST[0][i] = A[i]; } for (int i = 0; i < LOG - 1; i++){ for (int j = 0; j < N - (1 << i); j++){ ST[i + 1][j] = min(ST[i][j], ST[i][j + (1 << i)]); } } } T range_min(int L, int R){ int d = 31 - __builtin_clz(R - L); return min(ST[d][L], ST[d][R - (1 << d)]); } }; template struct lazy_segment_tree{ int N; vector ST; vector lazy; lazy_segment_tree(vector A){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector(N * 2 - 1, 0); lazy = vector(N * 2 - 1, 0); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void eval(int i){ if (i < N - 1){ lazy[i * 2 + 1] = max(lazy[i * 2 + 1], lazy[i]); lazy[i * 2 + 2] = max(lazy[i * 2 + 2], lazy[i]); } ST[i] = max(ST[i], lazy[i]); } void range_chmax(int L, int R, T x, int i, int l, int r){ eval(i); if (R <= l || r <= L){ return; } else if (L <= l && r <= R){ lazy[i] = max(lazy[i], x); eval(i); } else { int m = (l + r) / 2; range_chmax(L, R, x, i * 2 + 1, l, m); range_chmax(L, R, x, i * 2 + 2, m, r); ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void range_chmax(int L, int R, T x){ return range_chmax(L, R, x, 0, 0, N); } T range_max(int L, int R, int i, int l, int r){ eval(i); if (R <= l || r <= L){ return 0; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r)); } } T range_max(int L, int R){ return range_max(L, R, 0, 0, N); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; for (int i = 0; i < T; i++){ int N; cin >> N; vector A(N); for (int j = 0; j < N; j++){ cin >> A[j]; } vector B(N); for (int j = 0; j < N; j++){ cin >> B[j]; } bool ok = true; for (int j = 0; j < N; j++){ if (B[j] < A[j]){ ok = false; } } if (!ok){ cout << "No" << "\n"; } else { vector> P(N); for (int j = 0; j < N; j++){ P[j] = make_pair(A[j], j); } sort(P.begin(), P.end()); lazy_segment_tree ST1(A); sparse_table ST2(B); for (int j = 0; j < N; j++){ int x = P[j].first; int p = P[j].second; int tv1 = p, fv1 = -1; while (tv1 - fv1 > 1){ int mid = (tv1 + fv1) / 2; if (ST1.range_max(mid, p + 1) <= x && ST2.range_min(mid, p + 1) >= x){ tv1 = mid; } else { fv1 = mid; } } int tv2 = p + 1, fv2 = N + 1; while (fv2 - tv2 > 1){ int mid = (tv2 + fv2) / 2; if (ST1.range_max(p, mid) <= x && ST2.range_min(p, mid) >= x){ tv2 = mid; } else { fv2 = mid; } } ST1.range_chmax(tv1, tv2, x); } for (int j = 0; j < N; j++){ if (ST1.range_max(j, j + 1) != B[j]){ ok = false; } } if (ok){ cout << "Yes" << "\n"; } else { cout << "No" << "\n"; } } } }