intmain(){ int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", a + i); }
for (int i = 1; i <= m; i++) { scanf("%d", p + i); } sort(p + 1, p + m + 1); int start = 1; intend = 1; for (int i = 1; i <= m; i++) { if (i == 1) { start = p[i]; } if (i != 1 && p[i] > p[i - 1] + 1) { sort(a + start, a + end + 1); start = p[i]; }
end = p[i] + 1; }
sort(a + start, a + end + 1);
bool res = true; for (int i = 1; i < n; i++) { if (a[i + 1] < a[i]) { res = false ; break; } }
intmain(){ ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int temp[105]; for (int i = 0; i < n; i++) { cin >> a[i]; temp[i] = a[i]; } for (int i = 0; i < m; i++) { int num; cin >> num; p[i] = num - 1; }
sort(temp, temp + n); sort(p, p + m);
bool visit[105]; // visit[i] == true 代表下标为i的已经访问 memset(visit, false, sizeof(visit)); bool res = true; for (int i = 0; i < n; i++) { // 排序后的列表往后找
int index = 0; boolfind = false;
// 在原数组中查找未被匹配过的元素(有重复元素的情况下) for (int j = 0; j < n; j++) { if (!visit[j] && temp[i] == a[j]) { visit[j] = true; index = j; break; } }
if (index == i) { // 位置相同,不用交换。 continue; }
int low = min(index, i); int high = max(index, i); int p_indix_start = -1; // 在p数组中查找第一个等于low的元素 for (int k = 0; k < m; k++) { if (p[k] == low) { p_indix_start = k; break; } if (p[k] > low) { break; } }
// 若找到第一个等于low的元素,则查询后续元素是否都是连续递增的(直到high-1) if (p_indix_start != -1) { for (int k = p_indix_start; k < m; k++) { if (p[k] == high - 1) { find = true; break; } elseif (k + 1 >= m || p[k] != p[k + 1] - 1) { find = false; break; } } } // 若没找到第一个等于low的元素,则一定无法到达 else { find = false; } // 若某元素无法排序,则整个数组必定无法排序 if (!find) { res = false; break; } } if (res) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return0; }