Hyper Tree Problem
Time limit4sMemory limit1024 MB
Given a weighted tree, update edge weights with bitwise AND and report, for a query vertex, the sum over all vertices of the OR of edge weights on the path.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Union-find, Tree, Divide and conquer
- Solved
- No attempts yet
Problem
The tree has vertices numbered from to , and its edges are numbered from to in input order. Edge has weight .
A total of queries of two types are given. For each query of type 2, print the answer.
1 e v: Change the weight of edge to . Here is the Bitwise AND operation.2 n: Print . is the Bitwise OR of all edge weights on the unique path between vertices and . If , then .
Input
The first line contains and , separated by a space.
Each of the next lines contains , , and , separated by spaces. Edge connects vertices and , and its initial weight is .
Each of the next lines is one of the following queries.
1 e v:2 n:
All numbers in the input are integers. At least one query of type 2 is guaranteed.
Output
For each query of type 2, print the result on its own line, in the order the queries are given.