description
http://codevs.cn/problem/3303/
Analyze
The topic is an ordinary splay subject that implements interval rollover by marking. The flip card was previously sent with the same title. The main thing here is to carefully analyze the implementation of the tag and some problems. Do some preparatory work for the subsequent maintenance sequence.
The
- first clarifies why it is possible to record rollover information in a tagged manner. A subtrees tree in the
Splay represents a contiguous interval, because Splay is BST, which satisfies the left son (LC) <= root node of the node O (o) <= right son (RC). And if O is the left son of its parent node, RC must be smaller than the parent of O; if O is its parent The right son of the knot, the LC must be larger than the parent node of O. This ensures that the interval is continuous, and that the sequence of the interval is the result of the subtrees tree's first order traversal.
- Since the subtree is a closed interval, it can be changed to indicate that the interval has been flipped. So how do you mark the next pass? First, the left and right sub-tree of the root node should be exchanged, that is, the root node O is the boundary point, compared to O-small LC Exchange to O-large RC, than O The large RC is switched to a smaller LC than O. Then, the left and right sub-nodes are the root node to upload the marker to the left and right two subtrees trees respectively ... Layer-by-layer transmission, the end of the entire range of the flip. This is the idea of divided treatment. Of course, the tag is passed one step when it is needed in the implementation.
- Last question, when do you mark the next pass? How do I maintain its parent and ancestor values after the next pass?
There are two things here, the first is the bottom-up splay, which needs to mark all nodes encountered at find () , and find () goes through all the nodes that reach the target node. The other is a top-down splay that needs to be tagged with the root node and the child node where the target is located in the splay operation. It is necessary to find the target node in the direction of the root node (the left subtree or the right subtree), but also to find the target node in the direction of the child nodes.
Do you need to maintain the value of ancestor nodes after the tag is passed? There is no need for too much maintenance because the splay operation comes with maintenance operations-the rotation operation.
Code
https://code.csdn.net/snippets/608231
codevs-3303-Flip Interval