#P10662. BZOJ4202 石子游戏

BZOJ4202 石子游戏

Problem Description

The Stone Game is a type of game that many people enjoy. This kind of game is usually related to moving stones and choosing whether to take them, and it often brings a lot of fun.

There is a type of stone game on a tree with the following rules: on a rooted tree, each node has a certain number of stones. Two players take turns to play. Each turn, a player may move at most mm stones to the parent of a node, and in one turn they can only move stones from one node. Obviously, the root has no parent, so once a stone is moved to the root, it can no longer be moved. The question is: when playing this game on the subtree rooted at some node, does the first player have a winning strategy.

To make the game harder, we make some small changes. Now, this tree may grow new nodes. Also, the number of stones on each node may change. Please answer: when playing this stone game on the subtree rooted at some node, does the first player have a winning strategy. This problem requires mandatory online processing.

Input Format

The first line contains two integers n,mn, m, meaning that initially there are nn nodes, and each move can move at most mm stones.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \dots, a_n, representing the initial number of stones, where node 11 is the root.

The next n1n - 1 lines each contain two integers u,vu, v, indicating that there is an edge between uu and vv.

The next line contains a positive integer tt, denoting the number of operations.

The next tt lines each describe one operation. The first number of each line is the operation type:

  • If it is 11, it is followed by an integer vv, meaning to ask whether the first player must win when playing the game in the subtree of vv.
  • If it is 22, it is followed by two integers x,yx, y, meaning to modify the number of stones at node xx to yy.
  • If it is 33, it is followed by three integers u,v,xu, v, x, meaning to add a child vv to node uu, whose initial number of stones is xx.

Output Format

For each query, output Yes if the first player must win; otherwise output No.

Note: The testdata is processed with mandatory online handling. For each operation, except for the type number, all other numbers need to be XORed with the number of previous answers that are Yes.

2 1000
0 0
1 2
1
1 1
No

Hint

For 100%100\% of the data, 1n,t5×1041 \leq n, t \leq 5 \times 10^4. Also, it is guaranteed that at any time, the number of nodes in the tree and the node indices will not exceed 10510^5. All other values are within the range of int.

Translated by ChatGPT 5