#P8265. [Ynoi Easy Round 2020] TEST_63
[Ynoi Easy Round 2020] TEST_63
Problem Description
You are given a forest consisting of rooted trees with vertices (initially there are no edges, and each vertex is the root of a rooted tree). The vertices are labeled with integers from to .
You need to maintain the Heavy-Light Decomposition (HLD) structure of the forest, defined as follows:
For each vertex , let the set of its children be . If is not a root, let its parent be .
The subtree size of a vertex , denoted , is defined as $1+\sum\limits_{u\in\mathrm{children}(w)}\mathrm{size}(u)$.
If a vertex is not a leaf (i.e., ), then its heavy child is defined as $\mathrm{arg}\max_{u\in\mathrm{children}(w)}size(u)\cdot n+\max(u,\mathrm{hc}(u),\mathrm{hc}(\mathrm{hc}(u)),\dots)$. That is, it is the child with the largest subtree size. If there are multiple children with the same subtree size, choose the one whose heavy chain (within the subtree rooted at ) contains the largest maximum vertex label.
A heavy chain is a sequence of vertices satisfying:
- is a root, or .
- .
In a tree, each vertex belongs to exactly one heavy chain.
The weight of a heavy chain is , i.e., the bitwise XOR of the vertex labels in the sequence.
You need to perform operations in order. The operations are:
- Add edge: given two vertices , make the root of the rooted tree containing (let the sequence of vertices satisfy , is the root, and are directed edges in the rooted tree containing ; reverse these edges to to make the root). Then add the directed edge . It is guaranteed that before this operation, and are in different rooted trees.
- Delete edge: given two vertices , delete the directed edge between and (it may be or ). It is guaranteed that this edge existed before.
- Query: given an integer , suppose there are currently heavy chains. Sort all existing heavy chains by their weights in increasing order, and ask for the -th smallest weight.
Input Format
The first line contains two integers n m.
The next lines each contain four integers o a b k. If , it means first add the edge , then query . If , it means first delete the edge , then query .
Output Format
Output lines, each containing one integer, in order, which are the results of each query.
5 10
1 4 2 5
1 1 4 2
1 2 5 3
0 4 2 3
1 4 3 4
1 1 5 3
0 1 5 4
0 5 2 4
0 1 4 1
1 5 2 3
1
5
2
7
7
6
7
2
1
7
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
This problem uses subtask-based judging.
There are test points. All test points satisfy , , , , , , and are all integers.
The testdata may have the following properties:
-
Property 1: The operations are generated randomly using the following strategy, repeated until an operation sequence of lines is generated:
-
Uniformly choose three integers in . If are in different rooted trees, generate a line
1 x y k. Otherwise, if is not a root, uniformly generate one of0 x father(x) kor0 father(x) x k. Otherwise, do nothing. -
Property 2: , and for , the -th line of the testdata is
1 a i k, where is chosen uniformly from the integers in . -
Property 3: , and for , the -th line of the testdata is
1 i b k, where is chosen uniformly from the integers in . -
Other constraints on .
The properties of each test point are:
Test point 1: , satisfies Property 1, 10 points.
Test point 2: , satisfies Property 1, 10 points.
Test point 3: , satisfies Property 1, 10 points.
Test point 4: satisfies Property 2, 15 points.
Test point 5: satisfies Property 3, 15 points.
Test points 6 to 10: satisfy Property 1, 20 points.
Test points 11 to 31: no special constraints, 20 points.
Translated by ChatGPT 5