#abc367f. F - Rearrange Query

F - Rearrange Query

Score : 500500 points

问题陈述

你得到了两个正整数序列,长度为 NNA=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)B=(B1,B2,,BN)B=(B_1,B_2,\ldots,B_N)

你需要按顺序处理 QQ 个查询。第 ii 个查询如下所述。

  • 你得到了正整数 li,ri,Li,Ril_i,r_i,L_i,R_i。如果能够将子序列 (Ali,Ali+1,,Ari)(A_{l_i},A_{l_i+1},\ldots,A_{r_i}) 重新排列以匹配子序列 (BLi,BLi+1,,BRi)(B_{L_i},B_{L_i+1},\ldots,B_{R_i}),则打印 Yes,否则打印 No

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given sequences of positive integers of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,,BN)B=(B_1,B_2,\ldots,B_N).

You are given QQ queries to process in order. The ii-th query is explained below.

  • You are given positive integers li,ri,Li,Ril_i,r_i,L_i,R_i. Print Yes if it is possible to rearrange the subsequence (Ali,Ali+1,,Ari)(A_{l_i},A_{l_i+1},\ldots,A_{r_i}) to match the subsequence (BLi,BLi+1,,BRi)(B_{L_i},B_{L_i+1},\ldots,B_{R_i}), and No otherwise.

Constraints

  • 1N,Q2×105 1\leq N,Q\leq 2\times 10^5
  • 1Ai,BiN 1\leq A_i,B_i\leq N
  • 1liriN 1\leq l_i \leq r_i\leq N
  • 1LiRiN 1\leq L_i \leq R_i\leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

l1l_1 r1r_1 L1L_1 R1R_1

l2l_2 r2r_2 L2L_2 R2R_2

\vdots

lQl_Q rQr_Q LQL_Q RQR_Q

Output

Print QQ lines. The ii-th line should contain the answer to the ii-th query.

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
  • For the 1st query, it is possible to rearrange (1,2,3)(1,2,3) to match (2,3,1)(2,3,1). Hence, we print Yes.
  • For the 2nd query, it is impossible to rearrange (1,2)(1,2) in any way to match (1,4,2)(1,4,2). Hence, we print No.
  • For the 3rd query, it is impossible to rearrange (1,2,3,2)(1,2,3,2) in any way to match (3,1,4,2)(3,1,4,2). Hence, we print No.
  • For the 4th query, it is possible to rearrange (1,2,3,2,4)(1,2,3,2,4) to match (2,3,1,4,2)(2,3,1,4,2). Hence, we print 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
}