Home => ProblemSet => 3.2-53:Prefix Equality
Problem2006--3.2-53:Prefix Equality

2006: 3.2-53:Prefix Equality

Time Limit: 1 Sec  Memory Limit: 128 MB  Submit: 0  Solved: 0
[ Submit ] [ Status ] [ Creator: ][ 参考程序 ]

Description

You are given integer sequences A=(a1,…,aN) and  B=(b1,…,bN), each of length N.
For i=1,...,Q, answer the query in the following format.
  • If the set of values contained in the first xi terms of A, (a1,…,axi), and the set of values contained in the first yi terms of B, (b1,…,byi), are equal, then print Yes; otherwise, print No.
题意:给出两段整数序列a,b,接着是q次询问,询问给出两个整数x,y,问a的前x位数字和b的前y位数字种类是否完全相同。

Input

Input is given from Standard Input in the following format:
N
a1……aN
b1……bN
Q
x1 y1

xyQ

Output

Print Q lines. The i-th line should contain the response to the i-th query.

Sample Input Copy

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 Copy

Yes
Yes
Yes
No
No
Yes
No

HINT

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

  • 1≤N,Q≤2×105
  • 1≤ai,bi≤109
  • 1≤xi,yi≤N
  • All values in input are integers.

Source/Category