#P6630. [ZJOI2020] 传统艺能
[ZJOI2020] 传统艺能
Description
Bob likes segment trees.
As everyone knows, the second problem of ZJOI contains many segment trees.
Bob has a generalized segment tree whose root is . Bob needs to perform range lazy-tag operations on this segment tree. Each operation uniformly at random selects one sub-interval from all sub-intervals of . For every non-leaf node visited during this operation, Bob will push down the tag on this node; for every leaf node (i.e. a node where the recursion does not continue), Bob will set a tag on this node.
Bob wants to know: after operations, what is the expected number of nodes that have a tag.
【Precise definitions】
Segment tree: A segment tree is a binary tree where each node stores a segment. The root node stores the segment . For each node, if it stores and , let , then its left and right children store and respectively; if , then it is a leaf node.
Generalized segment tree: In a generalized segment tree, is not required to be exactly the midpoint of the interval, but it must still satisfy . It is not hard to see that in a generalized segment tree, the depth of the tree can reach .
The core of a segment tree is lazy tags. Below is pseudocode for a generalized segment tree with lazy tags, where the tag array represents lazy tags:

Note that when processing a leaf node, once it gets a tag, this tag will remain forever.
You can also understand the problem as follows: There is a generalized segment tree, and each node has an value. Initially, all values in the tag array are . Bob will perform operations. Each operation uniformly at random selects an interval and executes MODIFY(root,1,n,l,r);.
In the end, the expected number of all Node such that tag[Node]=1 is the value you need to compute.
Input Format
The first line contains two integers .
The next line contains integers : in preorder traversal order, they give the split position of every non-leaf node in the generalized segment tree. You can also understand it like this: starting from a tree with only the root node , each time you read an integer, you split the current node whose interval contains this integer once, and finally you obtain a generalized segment tree with nodes.
It is guaranteed that the given integers form a permutation. It is not hard to see that with this information, a unique generalized segment tree on can be determined.
Output Format
Output one integer, representing the expected value modulo . That is, if the expected value in lowest terms is , you need to output an integer such that .
3 1
1 2
166374060
5 4
2 1 3 4
320443836
Hint
The sample input/output for is provided in the attachment.
Sample explanation
The input segment tree is .
If the operation is , the number of tagged nodes is . If the operation is , the number of tagged nodes is . Therefore, the answer is .
| Test Point | Other Constraints | ||
|---|---|---|---|
| None | |||
| None | |||
| None | |||
| None | The input segment tree is a complete binary tree | ||
| Each is uniformly random in | |||
| None | |||
| None |
For of the data, .
Translated by ChatGPT 5
京公网安备 11011102002149号