#d11207. 前缀集

前缀集

Prefix Sets

Problem Source

Click here

Problem Description

For a sequence aa, define its prefix set S(a,i)S(a, i) as the set of the first ii elements a[1]…a[i]a[1]\dots a[i].

Given two sequences a,ba, b of length nn, and mm queries. Each query gives two positions i,ji, j. You need to determine whether the prefix set S(a,i)S(a, i) equals the prefix set S(b,j)S(b, j).

Input Format

The first line contains an integer nn (n≤5×105n \le 5 \times 10^5).

The next two lines each contain nn integers, describing aa and bb respectively (1≤ai,bi≤1091 \le a_i, b_i \le 10^9).

The next line contains an integer mm (m≤5×105m \le 5 \times 10^5).

The following mm lines each contain two integers ii (1≤i≤n1 \le i \le n), jj (1≤j≤n1 \le j \le n), representing a query on S(a,i)S(a, i) and S(b,j)S(b, j).

Output Format

Output mm lines. For each query, if the two prefix sets are equal, print Y; otherwise print N.

Sample Input

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

Sample Output

Y
Y
Y
N
N
Y
N