#abc250e. E - Prefix Equality

E - Prefix Equality

Score : 500500 points

问题描述

你已知两个整数序列 A=(a1,,aN)A = (a_1,\ldots,a_N)B=(b1,,bN)B = (b_1,\ldots,b_N),每个序列的长度均为 NN

对于 i=1,,Qi=1,\ldots,Q,以以下格式回答查询:

  • 如果在 AA 序列的前 xix_i(a1,,axi)(a_1,\ldots,a_{x_i}) 中包含的值集合与在 BB 序列的前 yiy_i(b1,,byi)(b_1,\ldots,b_{y_i}) 中包含的值集合相等,则输出 Yes;否则,输出 No

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

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 1

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.

update @ 2024/3/10 10:41:22