#P10145. [WC2024] 线段树
[WC2024] 线段树
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 differ from the one you are familiar with.
- A segment tree is a rooted binary tree. Each node corresponds to an interval on the sequence, and 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 corresponds to and its right child corresponds to .
- The shape of the segment tree depends on the choice of the split point for each non-leaf node.
- For range sum problems, for the sequence , each node in the segment tree maintains the value .
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 preorder traversal of the nodes in the segment tree is $[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 maintained values of all nodes in are known, then the sum of each interval can be uniquely determined.
For example, if and are known, then the sum of can be determined. Conversely, if and are known, then the sum of can also be determined. But if only and are known, then the sum of 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 integer in one line, 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 sums of and at the same time, can you determine the sum of . Therefore, the total number of valid ways 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.
- .
- .

Translated by ChatGPT 5