#P10799. 「CZOI-R1」三角形与树

    ID: 12038 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学倍增树状数组O2优化最近公共祖先 LCA树链剖分

「CZOI-R1」三角形与树

Background

CaiZi hates triangles, but he likes trees.

2024.8.15 Update: Added a set of hack testdata.

Problem Description

Given a tree with nn nodes, numbered from 11 to nn. Each node has a weight, and initially the weight of node ii is aia_i. There are qq operations in total.

  1. XOR the weights of all nodes on the simple path from node xx to node yy by kk.
  2. Determine whether it is possible to choose 33 distinct nodes on the simple path from node xx to node yy, and use the weights of these 33 nodes as side lengths to form a triangle. In particular, if it is impossible to choose 33 nodes, it is also considered impossible to form a triangle.

The simple path from node xx to node yy is the path from xx to yy that does not traverse any edge more than once. All nodes on it are the nodes on this path, including node xx and node yy.

It is guaranteed that at any time, no node will have weight 00.

Input Format

The first line contains 22 integers n,qn, q, representing the number of nodes in the tree and the number of operations.

The second line contains nn integers aia_i, representing the initial weight of node ii.

The next n1n - 1 lines each contain 22 integers u,vu, v, representing an edge of the tree.

The next qq lines each start with 11 integer ss, representing the operation type.

  • If s=1s = 1, then read 33 integers u,v,wu, v, w, representing an update operation.
  • If s=2s = 2, then read 22 integers u,vu, v, representing a query operation.

Output Format

For each query operation, output 11 if the condition can be satisfied; otherwise output 00. Output all answers consecutively, with no spaces or newlines.

5 5
1 2 3 4 5
1 2
1 3
2 4
2 5
2 1 2
2 3 4
1 3 5 4
2 2 3
2 1 5
0110

Hint

Sample Explanation

In the 1st operation, there are fewer than 33 node weights on the simple path.
In the 2nd operation, the node weights on the simple path are 1,2,3,41, 2, 3, 4.
After the 3rd operation, the node weights of nodes 1n1 \sim n are 5,6,7,4,15, 6, 7, 4, 1.
In the 4th operation, the node weights on the simple path are 5,6,75, 6, 7.
In the 5th operation, the node weights on the simple path are 1,5,61, 5, 6.

Constraints

This problem uses bundled tests.

  • Subtask #1 (8 pts8\text{ pts}): n,q3×103n, q \le 3 \times 10^3.
  • Subtask #2 (8 pts8\text{ pts}): The tree is guaranteed to be a "chrysanthemum" (juhua).
  • Subtask #3 (20 pts20\text{ pts}): In every update operation, x=yx = y.
  • Subtask #4 (24 pts24\text{ pts}): The tree is guaranteed to be a chain.
  • Subtask #5 (40 pts40\text{ pts}): No special properties. Depends on Subtask #1 to Subtask #4.

For 100%100\% of the data, 1u,vn1051 \le u, v \le n \le 10^5, 1q1051 \le q \le 10^5, s{1,2}s \in \{1, 2\}, and 1ai,w23111 \le a_i, w \le 2^{31} - 1.

Translated by ChatGPT 5