#P17417. 【MX-X31-T7】「FAOI-R14」Hello & Bye, Days(加强版)
【MX-X31-T7】「FAOI-R14」Hello & Bye, Days(加强版)
Background
on this lonely day
Cheers for the farewell against the light.
Maybe I am just a puppet.
Forced to cry before an inevitable ending.
Problem Description
The original problem is P17411, but it was passed by some solutions that were not intended to pass, so extra constraints were added to make the memory and time limits stricter.
You are given a tree with nodes. You need to maintain a set of key nodes , which is empty at the beginning. Let be the distance between and on the tree, and define .
Each node also has a positive integer weight .
Then there are operations. The -th operation is of one of the following two types:
-
1 x: If is in , delete from ; otherwise, add into . -
2 x: Output . It is guaranteed that here. That is, count how many nodes satisfy that is one of the closest key nodes to .
Some test points require you to answer queries online.
Input Format
The first line contains three integers , representing the number of nodes, the number of operations, and a parameter related to forced online queries.
Next lines each contain a pair of integers , representing an edge.
The next line contains integers , representing the weight of each node.
Next lines each contain two integers , where is the operation type, and is the information before decryption.
Let
$$x=z\mathbin{\operatorname{xor}}\mathrm{(lastans\times t)},$$then is the real node index for this operation, where is the answer to the previous query, initially .
It is guaranteed that:
- After decryption, .
- For operation
2, after decryption . - After each operation is executed, the set is non-empty.
The encrypted node index in the input may be .
Output Format
Output several lines, each line is the answer to one query.
5 7 0
1 2
2 3
3 4
4 5
1 1 1 1 1
1 1
2 1
1 5
2 1
2 5
1 1
2 5
5
3
3
5
Hint
Sample Explanation
The tree is a chain:
-
After adding key node , . The closest key node of every node is , so the first query outputs .
-
After adding key node , :
- For key node , the nodes that satisfy the condition are .
- For key node , the nodes that satisfy the condition are .
Node has distance to both key nodes, so it will be counted in both queries.
- Finally, delete key node . Now . The closest key node of every node is , so the output is .
Constraints
This problem has subtasks.
- For of the testdata, .
- For of the testdata, .
- For another of the testdata, the tree is a chain.
- For another of the testdata, .
- For of the testdata, , , , , .
Translated by ChatGPT 5