#P10880. [JRKSJ R9] 莫队的 1.5 近似构造
[JRKSJ R9] 莫队的 1.5 近似构造
Background
The construction of 2D Mo's algorithm can be seen as a TSP problem on a complete graph where the edge weight between is . Clearly, the edge weights of any Mo ordering satisfy the triangle inequality.
Compute the minimum spanning tree, then take all vertices with odd degree, and run a minimum-weight matching on the induced subgraph to obtain . Add to the minimum spanning tree, and then find an Euler tour.
Note that , (a solution for can give two matchings; consider the smaller one), and the total edge weight of the Euler tour is no less than the weight of the solution given by the Euler tour, which yields a result .
Problem Description
You are given a permutation of and intervals on this permutation.
For a value-domain interval :
- Define the “value of this value-domain interval when choosing ” as how many numbers in belong to the value-domain interval .
- Define the value of the value-domain interval as the maximum of the above quantity over all .
That is, the value of the value-domain interval is $\displaystyle\max_{i=1}^m \sum_{j=l_i}^{r_i} [L\le a_j\le R]$.
Two intervals are defined to intersect if and only if there exists at least one integer contained in both intervals. Please choose several pairwise non-intersecting value-domain intervals such that the product of their values is maximized. Output this answer modulo .
Input Format
The first line contains two integers .
The second line contains integers denoting .
The next lines each contain two integers .
Output Format
Output one integer denoting the answer. Output the answer modulo .
3 3
1 2 3
1 2
1 3
2 3
3
10 10
7 9 4 5 8 3 2 1 6 10
3 7
2 6
1 2
3 4
8 9
1 2
2 6
5 8
6 9
4 5
12
60 30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
34 57
2 17
3 16
18 50
18 54
8 45
8 56
14 39
22 33
12 33
27 49
33 33
9 11
12 52
11 17
23 31
14 39
19 57
25 32
15 22
2 48
14 21
51 59
28 48
26 31
31 60
41 58
36 46
49 53
44 48
328034228
Hint
Sample Explanation 1
Choose the value-domain interval .
Sample Explanation 2
You can choose the value-domain intervals .
Sample Explanation 3
Sample 3 satisfies the special property.
Constraints and Notes
This problem uses bundled testdata.
| Special property | Score | ||
|---|---|---|---|
Special property: it is guaranteed that .
For all testdata, it is guaranteed that , , and is a permutation of .
Translated by ChatGPT 5