QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#4891. 树上的孤独

統計

时间限制2s,内存限制1G

题目背景

有两棵树小 A 和小 B,小 A 发育不良,小 B 发育的很好。

为了追上小 B 的发育,小A 开始了魔改之路。

题目描述

小 A 有 $n$ 个节点,小 B 有 $m$ 个节点。每一个节点都有一种颜色。小 A 和小 B 都以一号节点为根。

为了追赶小 B,小 A 进行了 $q$ 次发育操作。

对于每一次操作先读入一个整数 $P$ 表示操作类型。

若 $P=1$,表示一次询问,那么接下来读入四个整数 $P_1,P_2,P_3,P_4$。

我们令 $lt$ 为上一次询问的答案,那么令 $D_1=P_3\oplus lt,D_2=P_4\oplus lt$,$lt$ 初始时为 $0$。

小 A 希望你能回答出小 A 的 $P_1$ 子树内离 $P_1$ 距离不超过 $D_1$ 和小 B 的 $P_2$ 子树内离 $P_2$ 距离不超过 $D_2$ 的节点中一共有多少种不同的颜色。

若 $P=2$,表示小 A 对自己进行了一次魔改发育,接下来读入两个整数 $S_1,S_2$ 表示小 A 将自己的 $S_1$ 节点的颜色魔改为了 $S_2$。

输入格式

第一行读入三个整数 $n,m,q$。

接下来读入 $n-1$ 行,每行两个正整数 $u,v$,表示有一条边连接小 A 的 $u$ 和 $v$。

然后读入 $m-1$ 行,每行两个正整数 $u,v$,表示有一条边连接小 B 的 $u$ 和 $v$。

紧接着读入 $n$ 行,每行一个正整数 $v_1$,第 $i$ 行表示小 A 的第 $i$ 号节点的颜色。

还需要读入 $m$ 行,每行一个正整数 $v_2$,第 $i$ 行表示小 B 的第 $i$ 号节点的颜色。

最后再读入 $q$ 个询问,询问格式见题目描述。

输出格式

对于每一个询问单独输出一行,每行一个整数表示答案。

样例数据

样例输入

5 5 5
4 3
1 3
5 4
2 3
4 2
5 4
3 2
1 3
4
1
3
5
4
1
5
1
2
3
1 2 1 1 2
1 1 5 2 2
1 4 1 2 3
1 5 4 2 2
1 4 1 1 3

样例输出

2
2
2
2
3

子任务

$n\leq 20$,$m\leq 2\times 10^5$,$q\leq 10^6$

$P_1\leq n$,$P_2\leq m$,$1\leq P_3,P_4\leq 2\times 10^5$

  • Subtask 1 ($10\%$): $m,q \le 2\,000$
  • Subtask 2 ($20\%$): 不存在 $2$ 操作
  • Subtask 3 ($30\%$): $m,q \le 10^5$
  • Subtask 4 ($10\%$): $n = 1$
  • Subtask 5 ($30\%$): 五特殊限制。
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.