아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sequence

면접 대비

시간 제한1초메모리 제한512 MB

요약
색깔 공의 초기 배열과 목표 배열이 주어지고, 여러 구간 재배치 연산을 순서대로 적용해 목표 배열에 도달할 수 있는지 판정한다.
난이도

보통10점 중 5점

유형
배열, 그리디, 구간, 구현
정답자
아직 제출이 없습니다

문제

ZZX has a sequence of boxes numbered 1,2,…,n1, 2, \ldots, n. Each box can contain at most one ball.

You are given the initial configuration of the balls. For 1≤i≤n1 \le i \le n, if the ii-th box is empty, then a_i=0a\_i = 0, otherwise the ii-th box contains exactly one ball, the color of which is a_ia\_i, a positive integer. Balls of the same color cannot be distinguished.

ZZX will perform mm operations in order. During ii-th operation, he collects all the balls from boxes l_i,l_i+1,…,r_i−1,r_il\_i, l\_i + 1, \ldots, r\_i - 1, r\_i, and then arbitrarily puts them back into these boxes. Note that each box should always contain at most one ball.

ZZX wants to change the configuration of the balls from a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n to b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n using these operations. Please tell ZZX whether it is possible to achieve his goal.

입력

The first line contains an integer T≤60T \le 60. Then TT test cases follow. In each test case:

The first line of the test case contains two integers nn and mm (1≤n≤10001 \le n \le 1000, 0≤m≤10000 \le m \le 1000, sum of nn over all test cases does not exceed 20002000, sum of mm over all test cases does not exceed 20002000).

The second line contains a_1,a_2,…,a_na\_1, a\_2, \ldots ,a\_n (0≤a_i≤n0 \le a\_i \le n). The third line contains b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n (0≤b_i≤n0 \le b\_i \le n). Each of the next mm lines contains two integers l_il\_i and r_ir\_i (1≤l_i≤r_i≤n1 \le l\_i \le r\_i \le n).

출력

For each test case, print "Yes" or "No" on a separate line.

예제1

  1. 예제 1

    입력
    5
    4 1
    0 0 1 1
    0 1 1 1
    1 4
    4 1
    0 0 1 1
    0 0 2 2
    1 4
    4 2
    1 0 0 0
    0 0 0 1
    1 3
    3 4
    4 2
    1 0 0 0
    0 0 0 1
    3 4
    1 3
    5 2
    1 1 2 2 0
    2 2 1 1 0
    1 3
    2 4
    
    예상 출력
    No
    No
    Yes
    No
    Yes