#P10211. [CTS2024] 线段树
[CTS2024] 线段树
Problem Description
Little Y has recently learned how to use a segment tree to maintain a sequence and support range sum queries.
Below is the definition of the segment tree used in this problem. This definition may be different from the segment tree you are familiar with.
- A segment tree is a rooted binary tree. Each node corresponds to an interval on the sequence, where the root corresponds to .
- For each node, if its interval satisfies , then it is a leaf node. Otherwise, there exists an integer such that its left child represents and its right child represents .
- The shape of the segment tree depends on the choice of the split point for each non-leaf node.
- For the range sum problem, for the sequence , each node in the segment tree maintains the value of .
Little J has an array of length , . He does not know any value in , but he has a segment tree that maintains the range sums of . The segment tree is given by , where is the split point of the -th non-leaf node in the preorder traversal of the segment tree.
For example, if , then the nodes in the segment tree, in preorder traversal, are $[0, 5), [0, 2), [0, 1), [1, 2), [2, 5), [2, 4), [2, 3), [3, 4), [4, 5)$.
Little J has intervals . He wants to know: among all subsets of the segment tree nodes, how many subsets satisfy the following condition:
- If the values maintained by all nodes in are known, then the sum over each interval can be uniquely determined.
For example, if and are known, then the sum over can be determined. Conversely, if and are known, then the sum over can also be determined. But if only and are known, then the sum over or cannot be determined.
Since the answer can be very large, you need to output the answer modulo .
Input Format
The first line contains two integers , representing the array length and the number of intervals.
The second line contains integers .
The next lines each contain two integers , representing an interval.
Output Format
Output one line with one integer, representing the answer modulo .
2 1
1
0 2
5
2 1
1
1 2
5
5 2
2 1 4 3
1 3
2 5
193
10 10
5 2 1 3 4 7 6 8 9
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
70848
Hint
Explanation for Sample 1
Only when you directly know the total sum of , or when you know both the total sums of and , can you determine the total sum of . Therefore, the total number of valid choices is .
Constraints
For all testdata:
- .
- $1 \le M \le \min \{\frac{N(N+1)}{2}, 2 \times 10^5\}$.
- .
- It is guaranteed that correctly describes a segment tree.
- .
- .
Subtask 1 (6 points): .
Subtask 2 (18 points): .
Subtask 3 (9 points): .
Subtask 4 (17 points): .
Subtask 5 (10 points): .
Subtask 6 (13 points): .
Subtask 7 (7 points): .
Subtask 8 (20 points): No additional constraints.
Translated by ChatGPT 5