#P15717. [JAG 2023 Summer Camp #2] Disjoint-Sparse-Table Optimization
[JAG 2023 Summer Camp #2] Disjoint-Sparse-Table Optimization
题目描述
You are given an integer sequence of length and intervals . Here, satisfy , and each integer between and appears once as an end of an interval.
Your goal is to create a set of intervals to satisfy at least one of the following conditions for all .
- There exists an integer () such that and .
The cost of the set is defined as follows.
- The sum of for all intervals included in .
Find the minimum cost of the set that satisfies the condition.
输入格式
$$\begin{aligned} &Q \\ &L_1 \ R_1 \\ &\vdots \\ &L_Q \ R_Q \\ &A_1 \ A_2 \ \ldots \ A_{2Q-1} \end{aligned} $$The input satisfies the following constraints.
- All inputs consist of integers.
- Each integer from to appears in .
输出格式
Output the minimum cost of the set that satisfies the condition. Add a new line at the end of the output.
3
1 4
2 5
3 6
1 2 3 4 5
20
5
3 7
1 10
5 9
4 8
2 6
6 4 8 5 9 8 9 8 2
132
提示
In Sample Input 1, the optimal set is , where the cost is .