atcoder#ABC250E. [ABC250E] Prefix Equality

[ABC250E] Prefix Equality

Score : 500500 points

Problem Statement

You are given integer sequences A=(a1,,aN)A = (a_1,\ldots,a_N) and B=(b1,,bN)B = (b_1,\ldots,b_N), each of length NN.

For i=1,...,Qi=1,...,Q, answer the query in the following format.

  • If the set of values contained in the first xix_i terms of AA, (a1,,axi)(a_1,\ldots,a_{x_i}), and the set of values contained in the first yiy_i terms of BB, (b1,,byi)(b_1,\ldots,b_{y_i}), are equal, then print Yes; otherwise, print No.

Constraints

  • 1N,Q2×1051 \leq N,Q \leq 2 \times 10^5
  • 1ai,bi1091 \leq a_i,b_i \leq 10^9
  • 1xi,yiN1 \leq x_i,y_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 \ldots aNa_N

b1b_1 \ldots bNb_N

QQ

x1x_1 y1y_1

\vdots

xQx_Q yQy_Q

Output

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

5
1 2 3 4 5
1 2 2 4 3
7
1 1
2 2
2 3
3 3
4 4
4 5
5 5
Yes
Yes
Yes
No
No
Yes
No

Note that sets are a concept where it matters only whether each value is contained or not. For the 33-rd query, the first 22 terms of AA contain one 11 and one 22, while the first 33 terms of BB contain one 11 and two 22's. However, the sets of values contained in the segments are both {1,2}\{ 1,2 \}, which are equal. Also, for the 66-th query, the values appear in different orders, but they are still equal as sets.