#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 [l,r)[l, r) on the sequence, and the root corresponds to [0,n)[0, n).
  • For each node, if its interval [l,r)[l, r) satisfies rl=1r - l = 1, then it is a leaf node. Otherwise, there exists an integer m(l<m<r)m(l < m < r) such that its left child corresponds to [l,m)[l, m) and its right child corresponds to [m,r)[m, r).
  • The shape of the segment tree depends on the choice of the split point mm for each non-leaf node.
  • For range sum problems, for the sequence a0,a1,,an1a_0, a_1, \dots, a_{n-1}, each node [l,r)[l, r) in the segment tree maintains the value (al+al+1++ar1)(a_l + a_{l+1} + \cdots + a_{r-1}).

Little J has an array A0,A1,,AN1A_0, A_1, \dots, A_{N-1} of length NN. He does not know any value in AA, but he has a segment tree that maintains the range sums of AA. The segment tree is given by X1,X2,,XN1X_1, X_2, \dots, X_{N-1}, where XiX_i is the split point of the ii-th non-leaf node in the preorder traversal of the segment tree.

For example, if N=5,X=[2,1,4,3]N = 5, X = [2, 1, 4, 3], 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 MM intervals [L1,R1),[L2,R2),,[LM,RM)[L_1, R_1), [L_2, R_2), \dots, [L_M, R_M). He wants to know: among all subsets of the 2N12N - 1 segment tree nodes, how many subsets SS satisfy the following condition:

  • If the maintained values of all nodes in SS are known, then the sum of each interval [Li,Ri)[L_i, R_i) can be uniquely determined.

For example, if [0,1)[0, 1) and [1,2)[1, 2) are known, then the sum of [0,2)[0, 2) can be determined. Conversely, if [0,1)[0, 1) and [0,2)[0, 2) are known, then the sum of [1,2)[1, 2) can also be determined. But if only [0,2)[0, 2) and [2,4)[2, 4) are known, then the sum of [0,3)[0, 3) or [1,2)[1, 2) cannot be determined.

Since the answer can be very large, you need to output the answer modulo 998244353998244353.

Input Format

The first line contains two integers N,MN, M, representing the array length and the number of intervals.

The second line contains N1N - 1 integers X1,X2,,XN1X_1, X_2, \dots, X_{N-1}.

The next MM lines each contain two integers Li,RiL_i, R_i, representing an interval.

Output Format

Output one integer in one line, representing the answer modulo 998244353998244353.

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 [0,2)[0, 2), or when you know both the sums of [0,1)[0, 1) and [1,2)[1, 2) at the same time, can you determine the sum of [0,2)[0, 2). Therefore, the total number of valid ways is 22+1=52^2 + 1 = 5.

Constraints

For all testdata:

  • 2N2×1052 \le N \le 2 \times 10^5.
  • $1 \le M \le \min \{\frac{N(N+1)}{2}, 2 \times 10^5\}$.
  • 1iN1,1XiN1\forall 1 \le i \le N - 1, 1 \le X_i \le N - 1.
  • It is guaranteed that XiX_i correctly describes a segment tree.
  • 1iM,0Li<RiN\forall 1 \le i \le M, 0 \le L_i < R_i \le N.
  • ij,(Li,Ri)(Lj,Rj)\forall i \ne j, (L_i, R_i) \ne (L_j, R_j).

Translated by ChatGPT 5