当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5709:Claris Loves Painting

题目描述
Claris loves painting very much, so he painted a tree with beautiful colors.

The tree is a rooted tree with $n$ nodes which are conveniently labeled by $1,2,...,n$. Its root is the $1$-st node, and the $i$-th node is painted with color $c_i$. If $c_i=c_j$, then we think these two nodes have the same color.

We define $depth_i$ as the distance between the $i$-th node and the root, and simply, the distance between two adjacent nodes is always $1$.

Standing in front of this beautiful tree, Claris comes up with $m$ questions.
In each question, there are two integers $x$ and $d$, which means that Claris wants to know the number of different kinds of colors occur in $S$, where $S=\left\{v|v\ in\ x's\ subtree\ and\ depth_v\leq depth_x+d\right\}$.
输入解释
The first line of the input contains an integer $T(1\leq T\leq 500)$, denoting the number of test cases.

In every test case, there are two integers $n(1\leq n\leq 100000)$ and $m(1\leq m\leq 100000)$ in the first line, denoting the number of nodes and queries.
The second line contains $n$ integers, the $i$-th integer $c_i(1\leq c_i\leq n)$ denotes the color of the $i$-th node.
The third line contains $n-1$ integers, the $i$-th integer $f_{i+1}(1\leq f_i<i)$ denotes the father of the $i+1$-th node.
In the following $m$ lines, each line contains two integers $x(1\leq x\leq n)$ and $d(0\leq d<n)$, denoting each query.

The input has been encoded, if you read $x$ and $d$, the real $x$ and $d$ are $x \oplus last$ and $d \oplus last$, where $last$ is the answer of the previous query and $\oplus$ means bitwise exclusive-or.

Notice :
If it is the first query in this test case, then $last=0$.
It is guaranteed that $\sum n \leq 500000$ and $\sum m \leq 500000$.
输出解释
For each query output a single integer in a line, denoting the answer.
输入样例
1
5 8
1 3 3 2 2
1 1 3 3
1 0
0 0
3 0
1 3
2 1
2 0
6 2
4 1
输出样例
1
2
3
1
1
2
1
1
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5709

最后修改于 2020-10-25T23:24:59+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 256000/256000K(Java/Others)