#P5556. 圣剑护符

    ID: 4448 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>树状数组树链剖分,树剖线性基

圣剑护符

Description

The sacred sword in front of Xiao L and Xiao K is made of nn talismans, numbered 1,2,,n1,2,\ldots,n. There are n1n-1 spell-power lines connecting pairs of talismans, forming a tree structure.

After a long period of research, they found that the interaction between talismans is not complicated. Each talisman has an attribute value; the attribute value of talisman ii is denoted by viv_i. Each bit (00 or 11) in the binary representation of this value indicates whether the talisman has a certain attribute. The same bit position across all attribute values corresponds to the same attribute.

For a collection of talismans (a set of talismans), for each specific attribute, count how many talismans in the collection contain this attribute. If the count is even, then this collection produces interference, and the corresponding bit in the final attribute value is 00. If the count is odd, then after interference there remains the influence of one talisman, and the corresponding bit is 11. In other words, the attribute value of a set of talismans is the XOR sum of the attribute values of the individual talismans. The attribute value of the empty set is defined as 00.

Now, Xiao L wants to know: if we take all talismans on the simple path between two talismans xx and yy, can we find two different subsets such that the two subsets have the same attribute value (note that the empty set is also a subset of the set of all talismans on the path). Meanwhile, Xiao K will also take out all talismans on the path between the two talismans and adjust them, modifying the attribute values of all these talismans on some same bit positions (i.e., changing 00 to 11 and 11 to 00). This can be seen as XOR-ing the attribute values of all these talismans with a value.

Input Format

The first line contains two integers n,qn,q, representing the number of talismans and the number of operations by Xiao L and Xiao K.

The next line contains nn integers. The ii-th number is the attribute value viv_i of talisman ii.

The following n1n-1 lines each contain two integers x,yx,y, indicating that there is a spell-power line connecting talismans xx and yy. It is guaranteed to form a tree structure.

The next qq lines each describe an operation in one of the following forms:

  1. Update x y z: XOR the attribute values of all talismans on the simple path between talismans xx and yy with a value zz.

  2. Query x y: Determine whether, for the set of talismans on the simple path between talismans xx and yy, there exist two different subsets such that their attribute values are the same.

Output Format

For each Query operation, output one line containing YES or NO.

2 3
3 4
1 2
Query 1 2
Update 2 2 7
Query 2 1
NO
YES

Hint

For some reason, this problem uses bundled testdata. You can get the full score of a subtask only if you pass all test points in that subtask; otherwise you get 00 points.

Subtask#1Subtask\#1: 20pts20pts, the distance between xx and yy in the tree is at most 55.

Subtask#2Subtask\#2: 40pts40pts, n,q5000n,q\le 5000, 0vi,z2100\le v_i,z\le 2^{10}.

Subtask#3Subtask\#3: 40pts40pts, no special constraints.

For 100%100\% of the data, 1n,q1051\le n,q\le 10^5, 1x,yn1\le x,y\le n, 0vi,z<2300\le v_i,z<2^{30}.

Translated by ChatGPT 5