QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100 Difficulty: [show]

#9155. 集合

Statistics

小 Y 和小 S 在玩一个游戏。

给定正整数 $m$,定义基本集合为大小为 $3$,元素在 $1\sim m$ 内的集合。例如:给定 $m=4$,则集合 $\{1,2,3\}$ 与集合 $\{2,3,4\}$ 都是基本集合。

定义集合序列为由基本集合构成的序列,例如,$A=[\{1,2,3\},\{2,3,4\}]$ 是一个集合序列,其中 $A[1]=\{1,2,3\}$,$A[2]=\{2,3,4\}$ 都是基本集合。

对于一个 $1\sim m$ 的排列 $p[1],p[2],\dots,p[m]$ 与集合 $S\subseteq \{1,2,\dots,m\}$,定义 $f_p(S)$ 为将 $S$ 内每一个元素 $x$ 置换为 $p[x]$ 后所得到的集合,即 $f_p(S)=\{p[x]|x\in S\}$。

对于两个长度为 $k$ 的集合序列 $A,B$,定义 $A$ 和 $B$ 等价当且仅当存在一个 $1\sim m$ 的排列 $p$,使得 $A$ 置换排列 $p$ 后得到 $B$,即对于所有 $1\leq i\leq k$,$f_p(A[i])=B[i]$。

给定两个长度为 $n$ 的集合序列 $A,B$,有 $q$ 次询问。每次小 S 会询问小 Y,在给定 $l,r$ 的情况下,判断集合序列 $[A[l],A[l+1],\dots,A[r]]$ 与集合序列 $[B[l],B[l+1],\dots,B[r]]$ 是否等价。

时光荏苒,小 S 和小 Y 也会散去。而我们和一个人保持连接的方式就是记住,仅此而已。

输入格式

输入的第一行包含三个正整数 $n, m, q$,分别表示集合序列的长度、元素范围和询问次数。

输入的第二行包含 $3n$ 个正整数。第 $3i - 2, 3i - 1, 3i$($1 \le i \le n$)个正整数分别表示 $A[i]$ 的三个元素。保证这三个元素均在 $[1, m]$ 范围内且互不相同。

输入的第三行包含 $3n$ 个正整数。第 $3i - 2, 3i - 1, 3i$($1 \le i \le n$)个正整数分别表示 $B[i]$ 的三个元素。保证这三个元素均在 $[1, m]$ 范围内且互不相同。

接下来 $q$ 行,每行包含两个正整数 $l, r$,表示一次询问。

输出格式

输出 $q$ 行,每行包含一个字符串 YesNo,表示对应询问的两个序列是否等价。

样例一

输入

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

解释

以下用 $(l, r)$ 表示对 $l, r$ 的询问。

  • 对于询问 $(1, 1)$,令排列 $p = [1, 2, 4, 3]$,则 $f_p(A_1) = \{p[1], p[2], p[3]\} = \{1, 2, 4\} = B[1]$,因此该询问的两个序列等价。
  • 对于询问 $(1, 2), (1, 3), (1, 4)$,由于 $A[1] = A[2]$ 但 $B_1 \ne B_2$,因此这些询问的两个序列都不等价。
  • 对于询问 $(2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)$,令排列 $p = [2, 3, 4, 1]$,则 $f_p(A_2) = \{p[1], p[2], p[3]\} = \{2, 3, 4\} = B_2$,$f_p(A_3) = \{p[1], p[2], p[4]\} = \{1, 2, 3\} = B_3$,$f_p(A_4) = \{p[1], p[2], p[3]\} = \{2, 3, 4\} = B_4$,因此这些询问的两个序列都等价。

样例二

ex_2.inex_2.ans

这个样例满足测试点 $1 \sim 3$ 的约束条件。

样例三

ex_3.inex_3.ans

这个样例满足测试点 $8$ 的约束条件。

样例四

ex_4.inex_4.ans

这个样例满足测试点 $15, 16$ 的约束条件。

数据范围

对于所有测试数据保证:$1 \le n \le 2 \times 10 ^ 5$,$3 \le m \le 6 \times 10 ^ 5$,$1 \le q \le 10 ^ 6$。

测试点编号 $n\leq$ $m\leq$ $q\leq$
$1\sim 3$ $50$ $4$ $50$
$4\sim 6$ $5$
$7$ $200$ $4$ $200$
$8$ $5$
$9$ $4$ $2\times 10^5$
$10$ $5$
$11$ $2\times 10^5$ $4$
$12$ $5$
$13,14$ $2\,000$ $6\,000$ $10^3$
$15,16$ $10^6$
$17,18$ $2\times 10^4$ $6\times 10^4$ $10^2$
$19,20$ $2\times 10^5$ $6\times 10^5$ $10^6$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.