2211C1.md (2635B)
1 Source: https://codeforces.com/problemset/problem/2211/C1 2 3 C1. Equal Multisets (Easy Version) 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 This is the easy version of the problem. The difference between the versions is that in this version, the array $a$ is guaranteed to be a permutation. You can hack only if you solved all versions of this problem. 22 23 Given an array $a$ of size $n$, and a parameter $k$, an array $b$ is called cool if the following conditions hold: 24 25 * For each $i$ from $k$ to $n$, the array $[a_{i-k+1},a_{i-k+2},\ldots,a_i]$ is a rearrangement of $[b_{i-k+1},b_{i-k+2},\ldots,b_i]$. 26 27 You are given two arrays $a$ and $b$ of size $n$, and an integer $k$. The array $a$ is guaranteed to be a permutation$^{\text{∗}}$. The array $b$ only contains integers from $1$ to $n$, and $-1$. 28 29 Determine if it is possible to replace all $-1$ in $b$ with an integer from $1$ to $n$, such that $b$ is cool with respect to $k$. 30 31 $^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). 32 33 Input 34 35 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 36 37 The first line of each test case contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 2\cdot 10^5$). 38 39 The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le n$). In this version, it is guaranteed that each number from $1$ to $n$ appears exactly once. 40 41 The third line of each test case contains $n$ integers $b_1,b_2,\ldots,b_n$ ($1 \leq b_i \leq n$ or $b_i=-1$). 42 43 It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. 44 45 Output 46 47 For each test case, output YES if possible, and NO otherwise. You may print each letter in either uppercase or lowercase. 48 49 Example 50 51 Input 52 53 ``` 54 4 55 56 5 5 57 58 1 2 3 4 5 59 60 3 1 5 2 4 61 62 5 4 63 64 4 1 2 5 3 65 66 2 -1 -1 -1 -1 67 68 6 4 69 70 1 2 4 3 5 6 71 72 -1 -1 3 -1 -1 -1 73 74 6 4 75 76 1 2 4 3 5 6 77 78 -1 -1 3 3 -1 -1 79 ``` 80 81 Output 82 83 ``` 84 YES 85 86 NO 87 88 YES 89 90 NO 91 ``` 92 93 Note 94 95 In the first test case, we have $k=5$. The only subarray of size $5$ is $[1,5]$. We can see that $b$ is a rearrangement of $a$, so the answer is YES. 96 97 In the second test case, it can be shown that it is impossible to replace all $-1$ in $b$ such that every subarray of size $k=4$ are rearrangements of each other.