#P6177. 【模板】树分块 / Count on a tree II
【模板】树分块 / Count on a tree II
Background
Originally bzoj2589.
Problem Description
Given a tree with nodes, each node has an integer value. The value on node is .
There are queries. Each query gives . You need to decrypt them to get , and then ask: how many distinct integers are on the path from to .
Decryption method: .
Here, is the answer to the previous query. If there is no previous query, it is .
Input Format
The first line contains two integers and .
The second line contains integers. The -th integer represents .
In the next lines, each line contains two integers , describing an edge.
In the next lines, each line contains two integers , describing a query.
Output Format
For each query, output one integer per line, which is the answer.
8 2
105 2 9 3 8 5 7 7
1 2
1 3
1 4
3 5
3 6
3 7
4 8
2 5
3 8
4
4
Hint
For of the testdata, , , 。
Translated by ChatGPT 5