Processing math: 100%
XOR-path on tree - MarisaOJ: Marisa Online Judge

XOR-path on tree

Time limit: 1000 ms
Memory limit: 512 MB
Koishi is given a tree T, initially rooted at 1 - the only vertex. She also has q queries, each under the form of 1 in the following 2 types: - 1. Addxy: Add a vertex and make x its parent, connected by an edge of weight y. Denote |T| as the current size of T, then this vertex is numbered |T|+1. - 2. Queryab: Find the maximum XOR path from vertex a to any vertex in the subtree rooted at b. It is guaranteed that 1≤x,a,b≤|T| for all queries. Help Koishi find the answer for each query of type 2. ### Input - The first line contains an integer q. - The next q lines, each line contains the information of each query. ### Output - Print the answer for each query of type 2. ### Constraints - 1≤q≤2×105. - 1≤x,a,b≤|T|. - 0≤y≤230. ### Example Input: 4Add15Query11Add17Query11 Output: 57