#P2441. 角色属性树
角色属性树
Description
The Xumeng Fan Club is an interesting organization with a hierarchical tree structure. There is a president, who directly supervises several vice presidents. Each vice president, in turn, directly supervises several department heads, and so on.
Each member has a "moe" attribute, which is the product of several prime "moe elements" (for example, the value of cat ears is , timid is , blonde is , yandere is , twin-tails is , etc.).
For example, suppose a certain member has double cat ears and one timid trait; then her attribute value is .
Now, members care about the following question: for themselves, who is the nearest superior that shares at least one common moe element? For example, attribute values are all considered to share moe elements with the above member with attribute .
However, a member may change their attribute at any time. Ah... what a hassle.
Input Format
The first line contains , the number of members and the number of queries.
The second line contains numbers, the attribute values of members through .
The next lines each contain , meaning is the supervisor of .
Then lines follow, each of one of the two types:
:Query the nearest superior of member that shares at least one moe element.
:Change the attribute value of to .
Output Format
For each type query, output the required member ID. If there is no such superior, output .
4 6
10 8 4 3
1 2
2 3
3 4
1 1
1 2
1 3
1 4
2 1 9
1 4
-1
1
2
-1
1
Hint
Constraints:
- For of the testdata, there are no update operations.
- For of the testdata, , the number of updates .
- For of the testdata, , , the number of updates , and .
UPD: The testdata are random; this might be a fake problem.
Translated by ChatGPT 5
京公网安备 11011102002149号