int c[2 * maxn], cnt; voidinit_hash(){ for (int i = 1; i <= n; ++i) a[i] = A[i].k, c[i + n] = B[i].k; sort(c + 1, c + 2 * n + 1); cnt = unique(c + 1, c + 2 * n + 1) - c - 1; for (int i = 1; i <= n; ++i) { A[i].k = lower_bound(c + 1, c + cnt + 1, A[i].k) - c; B[i].k = lower_bound(c + 1, c + cnt + 1, B[i].k) - c; } }
voidwork(){ n = read(); c1 = c2 = 0; for (int i = 1; i <= n; ++i) B[i].k = read(); for (int i = 1; i <= n; ++i) B[i].v = read(); for (int i = 1; i <= n; ++i) A[i].k = read(); for (int i = 1; i <= n; ++i) A[i].v = read(); init_hash(); for (int i = 1; i <= n; ++i) { if (s1[A[i].k].empty()) a[++c1] = A[i].k; if (s2[B[i].k].empty()) b[++c2] = B[i].k; s1[A[i].k].insert(A[i].v); s2[B[i].k].insert(B[i].v); } sort(a + 1, a + c1 + 1); sort(b + 1, b + c2 + 1); int j = 1; for (int i = 1; i <= c1; ++i) { int id = a[i]; while (S.size() < s1[id].size()) { for (auto it : s2[b[j]]) S.insert(it); ++j; } for (it = s1[id].begin(); it != s1[id].end(); ++it) { int v = *it; It = S.upper_bound(v); if (It == S.end()) { for (int i = 1; i <= c1; ++i) s1[a[i]].clear(); for (int i = 1; i <= c2; ++i) s2[b[i]].clear(); S.clear(); puts("No"); return ; } S.erase(It); } } puts("Yes"); for (int i = 1; i <= c1; ++i) s1[a[i]].clear(); for (int i = 1; i <= c2; ++i) s2[b[i]].clear(); S.clear(); }
intmain(){ int T; cin >> T; while (T--) work(); return0; }