Calculate! 2
Time limit1sMemory limit512 MB
On a rooted tree, handle subtree XOR queries and subtree XOR updates, printing the XOR of a vertex and its descendants.
- Level
Medium7 of 10
- Topics
- Tree, Segment tree, DFS, Bit manipulation
- Solved
- No attempts yet
Problem
At Calculate! in the 3rd IUPC, Gyojeong answered every logic operation question that Ingyu asked. The 4th IUPC was held a year later, and this time Ingyu wanted to trip Gyojeong up, so he prepared a hard logic operation problem that Gyojeong cannot answer quickly.
The problem Ingyu prepared is the following.
- A tree with vertices is given. The root is always vertex 1. A tree is a connected graph with vertices and edges and no cycle.
- Each vertex carries one weight .
- queries are processed in the order they are given.
- A query of the form
1 xprints the XOR of the weights of vertex and all descendants of . - A query of the form
2 x yXORs into the weight of vertex and into the weight of every descendant of .
Gyojeong's answers have to be checked. Write a program that prints the answer to every query of the form 1 x.
Input
The first line contains the number of vertices () and the number of queries ().
Each of the next lines contains two integers and , which means that vertex and vertex are joined by an edge.
The next line contains numbers separated by spaces. The -th number is the weight () of vertex .
Each of the next lines contains one query, either 1 x or 2 x y, with and .
Output
For every query of the form 1 x, print the answer on its own line, in the order the queries are given.