#P10785. [NOI2024] 集合

[NOI2024] 集合

Problem Description

Xiao Y and Xiao S are playing a game.

Given a positive integer mm, define a basic set as a set of size 33 whose elements are within 1m1\sim m. For example, when m=4m=4, the sets {1,2,3}\{1,2,3\} and {2,3,4}\{2,3,4\} are both basic sets.

Define a set sequence as a sequence made up of basic sets. For example, A=[{1,2,3},{2,3,4}]A=[\{1,2,3\},\{2,3,4\}] is a set sequence, where A[1]={1,2,3}A[1]=\{1,2,3\} and A[2]={2,3,4}A[2]=\{2,3,4\} are both basic sets.

For a permutation p[1],p[2],,p[m]p[1],p[2],\dots,p[m] of 1m1\sim m and a set S{1,2,,m}S\subseteq \{1,2,\dots,m\}, define fp(S)f_p(S) as the set obtained by replacing each element xx in SS with p[x]p[x], i.e., fp(S)={p[x]xS}f_p(S)=\{p[x]|x\in S\}.

For two set sequences A,BA,B of length kk, define AA and BB to be equivalent if and only if there exists a permutation pp of 1m1\sim m such that applying the permutation pp to AA yields BB. That is, for all 1ik1\leq i\leq k, fp(A[i])=B[i]f_p(A[i])=B[i].

Given two set sequences A,BA,B of length nn, there are qq queries. Each time, Xiao S asks Xiao Y: given l,rl,r, determine whether the set sequence [A[l],A[l+1],,A[r]][A[l],A[l+1],\dots,A[r]] and the set sequence [B[l],B[l+1],,B[r]][B[l],B[l+1],\dots,B[r]] are equivalent.

Time flies, and Xiao S and Xiao Y will also drift apart. And the way we stay connected with someone is to remember, nothing more.

Input Format

The first line contains three positive integers n,m,qn,m,q, representing the length of the set sequences, the value range of elements, and the number of queries.

The second line contains 3n3n positive integers. The (3i2)(3i-2)-th, (3i1)(3i-1)-th, and (3i)(3i)-th integers (1in1\leq i\leq n) are the three elements of A[i]A[i]. It is guaranteed that these three elements are all in [1,m][1,m] and are pairwise distinct.

The third line contains 3n3n positive integers. The (3i2)(3i-2)-th, (3i1)(3i-1)-th, and (3i)(3i)-th integers (1in1\leq i\leq n) are the three elements of B[i]B[i]. It is guaranteed that these three elements are all in [1,m][1,m] and are pairwise distinct.

The next qq lines each contain two positive integers l,rl,r, representing one query.

Output Format

Output qq lines. Each line contains a string Yes\tt{Yes} or No\tt{No}, indicating whether the two sequences in the corresponding query are equivalent.

4 4 10
1 2 3 1 2 3 1 2 4 1 2 3
1 2 4 2 3 4 1 2 3 2 3 4
1 1
1 2
1 3
1 4
2 2
2 3
2 4
3 3
3 4
4 4
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
见 set2.in/ans
这个样例满足测试点 1-3 的约束条件。

见 set3.in/ans
这个样例满足测试点 8 的约束条件。

见 set4.in/ans
这个样例满足测试点 15、16 的约束条件。

Hint

[Sample 1 Explanation]

Below, (l,r)(l,r) denotes the query with parameters l,rl,r:

  • For query (1,1)(1,1), let the permutation be p=[1,2,4,3]p=[1,2,4,3]. Then fp(A1)={p[1],p[2],p[3]}={1,2,4}=B[1]f_p(A_1)=\{p[1],p[2],p[3]\}=\{1,2,4\}=B[1], so the two sequences for this query are equivalent.
  • For queries (1,2),(1,3),(1,4)(1,2),(1,3),(1,4), since A[1]=A[2]A[1]=A[2] but B[1]B[2]B[1]\neq B[2], the two sequences for these queries are all not equivalent.
  • For queries (2,2),(2,3),(2,4),(3,3),(3,4),(4,4)(2,2),(2,3),(2,4),(3,3),(3,4),(4,4), let the permutation be p=[2,3,4,1]p=[2,3,4,1]. Then fp(A2)={p[1],p[2],p[3]}={2,3,4}=B2f_p(A_2)=\{p[1],p[2],p[3]\}=\{2,3,4\}=B_2, fp(A3)={p[1],p[2],p[4]}={1,2,3}=B3f_p(A_3)=\{p[1],p[2],p[4]\}=\{1,2,3\}=B_3, fp(A4)={p[1],p[2],p[3]}={2,3,4}=B4f_p(A_4)=\{p[1],p[2],p[3]\}=\{2,3,4\}=B_4, so the two sequences for these queries are all equivalent.

[Constraints]

For all testdata, it is guaranteed that: 1n2×1051\leq n\leq 2\times 10^5, 3m6×1053\leq m\leq 6\times 10^5, 1q1061\leq q\leq 10^6, 1lrn1\leq l\leq r\leq n.

::cute-table{tuack}

Test Point ID nn\leq mm\leq qq\leq
131\sim 3 5050 44 5050
464\sim 6 55
77 200200 44 200200
88 55
99 44 2×1052\times 10^5
1010 55
1111 2×1052\times 10^5 44
1212 55
13,1413,14 20002\,000 60006\,000 10310^3
15,1615,16 10610^6
17,1817,18 2×1042\times 10^4 6×1046\times 10^4 10210^2
19,2019,20 2×1052\times 10^5 6×1056\times 10^5 10610^6

Translated by ChatGPT 5