P26044 [AtCoder] [ABC367F] Rearrange Query
普及+
题目描述

Problem Description

Given two sequences of positive integers of length $N$, $A=(A_1,A_2,\ldots,A_N)$ and $B=(B_1,B_2,\ldots,B_N)$.

You are given $Q$ queries to process sequentially. The $i$-th query is described as follows:

  • Given positive integers $l_i, r_i, L_i, R_i$. Determine if the subsequence $(A_{l_i}, A_{l_i+1}, \ldots, A_{r_i})$ can be rearranged to match $(B_{L_i}, B_{L_i+1}, \ldots, B_{R_i})$. If possible, output Yes; otherwise, output No.

Input Format

The input is given from the standard input in the following format:

$ N $ $ Q $ $ A_1 $ $ A_2 $ $\ldots$ $ A_N $ $ B_1 $ $ B_2 $ $\ldots$ $ B_N $ $ l_1 $ $ r_1 $ $ L_1 $ $ R_1 $ $ l_2 $ $ r_2 $ $ L_2 $ $ R_2 $ $\vdots$ $ l_Q $ $ r_Q $ $ L_Q $ $ R_Q $

Output Format

Output $Q$ lines. The $i$-th line should contain the answer for the $i$-th query.

Sample Input and Output

Sample Input #1

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

Sample Output #1

Yes
No
No
Yes

Sample Input #2

4 4
4 4 4 4
4 4 4 4
1 2 2 3
3 3 1 1
1 3 1 4
1 4 2 3

Sample Output #2

Yes
Yes
No
No

Notes/Hints

Constraints

  • $1\leq\ N,Q\leq\ 2\times\ 10^5$
  • $1\leq\ A_i,B_i\leq\ N$
  • $1\leq\ l_i\ \leq\ r_i\leq\ N$
  • $1\leq\ L_i\ \leq\ R_i\leq\ N$
  • All inputs are integers

Sample Explanation 1

  • For the 1st query, $(1,2,3)$ can be rearranged to match $(2,3,1)$. Therefore, output Yes.
  • For the 2nd query, no matter how $(1,2)$ is rearranged, it cannot match $(1,4,2)$. Therefore, output No.
  • For the 3rd query, no matter how $(1,2,3,2)$ is rearranged, it cannot match $(3,1,4,2)$. Therefore, output No.
  • For the 4th query, $(1,2,3,2,4)$ can be rearranged to match $(2,3,1,4,2)$. Therefore, output Yes.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 4 1 2 3 2 4 2 3 1 4 2 1 3 1 3 1 2 3 5 1 4 2 5 1 5 1 5
样例输出
Yes No No Yes