1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include <stack> #include <cctype> #include <cstdio> #include <algorithm> #include <iostream> #include <vector> #include <cstring> #include <climits> #include <queue> #include <string> #include <ctime> #include <iomanip> #include <cmath> #include <cstdlib> #include <map> using namespace std; bool iosig; char ch; template<class T> inline void read(T &x) { iosig = 0, x = 0; do { ch = getchar(); if (ch == '-') iosig = true; } while (!isdigit(ch)); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar(); if (iosig) x = -x; } int n, m, l, r; int a[1010], b[1010]; int acnt[1010], bcnt[1010]; struct Data { int l, r; } data[1010]; inline void solve() { read(n), read(m); memset(acnt, 0, sizeof(acnt)); memset(bcnt, 0, sizeof(bcnt)); for (register int i = 1; i <= n; i++) read(a[i]), acnt[a[i]]++; for (register int i = 1; i <= n; i++) read(b[i]), bcnt[b[i]]++; for (register int i = 1; i <= n; i++) { if (bcnt[i] > acnt[i]) { for (register int i = 0; i < m; i++) read(l), read(r); cout << "No\n"; return; } } for (int i = 0; i < m; i++) { read(data[i].l), read(data[i].r); if (data[i].l > data[i].r) swap(data[i].l, data[i].r); } for (register int i = 1; i <= n; i++) { bool flag = 0; register int pos = find(b + 1, b + n + 1, a[i]) - b; while (pos != n + 1) { l = r = i; for (register int j = 0; j < m; j++) { if (data[j].l <= l && data[j].r >= r) r = data[j].r, l = data[j].l; else if (l <= data[j].l && data[j].r >= r && r >= data[j].l) r = data[j].r; else if (data[j].l <= l && r >= data[j].r && data[j].r >= l) l = data[j].l; if (l <= pos && r >= pos) { flag = 1; break; } } if (flag) break; pos = find(b + pos + 1, b + n + 1, a[i]) - b; } if (!flag) { cout << "No\n"; return; } } cout << "Yes\n"; } int main() { int t; read(t); while (t--) solve(); return 0; }
|