WeirdSort

题意翻译

给出一个长度为 $n$ 的序列 $a$ 和一个长度为 $m$ 的序列 $p$,你需要按照以下规则给序列 $a$ 排序 对于所有 $(1 \le i \le m)$,$p_i$ 表示你可以交换 $a[p_i]$ 和 $a[p_i+1]$ 的值(可以操作任意次) 请求出是否能在以上限制条件下,保证排序后的原序列 $a$ 内元素值严格不递减 除了交换 $a[p_i]$ 和 $a[p_i+1]$ 之外,不可以有其他任何操作 ### 输入格式 **本题有多组数据** 第一行一个整数 $T$,表示数据的组数 接下来,对于每组数据: 第一行两个整数 $n,m$ 分别为序列 $a$ 和 $p$ 的长度 第二行 $n$ 个整数,表示序列 $a$ 第三行 $m$ 个整数,表示序列 $p$ ### 输出格式 $T$ 行,每行一个字符串 $\texttt{YES}$ 或 $\texttt{NO}$,表示是否能在给出的限制条件下,保证排序后的原序列 $a$ 内元素值严格不递减 **说明与提示** $1 \le T,a_i \le 100$ $1\le m < n \le 100$ $1\le p_i <n$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

题目描述

You are given an array $ a $ of length $ n $ . You are also given a set of distinct positions $ p_1, p_2, \dots, p_m $ , where $ 1 \le p_i < n $ . The position $ p_i $ means that you can swap elements $ a[p_i] $ and $ a[p_i + 1] $ . You can apply this operation any number of times for each of the given positions. Your task is to determine if it is possible to sort the initial array in non-decreasing order ( $ a_1 \le a_2 \le \dots \le a_n $ ) using only allowed swaps. For example, if $ a = [3, 2, 1] $ and $ p = [1, 2] $ , then we can first swap elements $ a[2] $ and $ a[3] $ (because position $ 2 $ is contained in the given set $ p $ ). We get the array $ a = [3, 1, 2] $ . Then we swap $ a[1] $ and $ a[2] $ (position $ 1 $ is also contained in $ p $ ). We get the array $ a = [1, 3, 2] $ . Finally, we swap $ a[2] $ and $ a[3] $ again and get the array $ a = [1, 2, 3] $ , sorted in non-decreasing order. You can see that if $ a = [4, 1, 2, 3] $ and $ p = [3, 2] $ then you cannot sort the array. You have to answer $ t $ independent test cases.

输入输出格式

输入格式


The first line of the input contains one integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. Then $ t $ test cases follow. The first line of each test case contains two integers $ n $ and $ m $ ( $ 1 \le m < n \le 100 $ ) — the number of elements in $ a $ and the number of elements in $ p $ . The second line of the test case contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 100 $ ). The third line of the test case contains $ m $ integers $ p_1, p_2, \dots, p_m $ ( $ 1 \le p_i < n $ , all $ p_i $ are distinct) — the set of positions described in the problem statement.

输出格式


For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order ( $ a_1 \le a_2 \le \dots \le a_n $ ) using only allowed swaps. Otherwise, print "NO".

输入输出样例

输入样例 #1

6
3 2
3 2 1
1 2
4 2
4 1 2 3
3 2
5 1
1 2 3 4 5
1
4 2
2 1 4 3
1 3
4 2
4 3 2 1
1 3
5 2
2 1 2 3 3
1 4

输出样例 #1

YES
NO
YES
YES
NO
YES