#P9594. 「Daily OI Round 1」Memory

    ID: 10671 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP线段树洛谷原创O2优化动态规划优化

「Daily OI Round 1」Memory

Problem Description

Given mm line segments. Each segment is described by four positive integers li,ri,ci,wil_i, r_i, c_i, w_i, where li,ril_i, r_i are the endpoints of the segment, cic_i is the type (category) of the segment, and wiw_i is the weight of the segment.

You need to select some segments such that the following condition is satisfied, and the total weight is maximized.

  • For any two different segments i,ji, j, either ci=cjc_i = c_j holds, or [li,ri][lj,rj]=[l_i, r_i] \cap [l_j, r_j] = \varnothing.

Input Format

The first line contains a positive integer mm, representing the number of segments.

The next mm lines each contain four positive integers li,ri,ci,wil_i, r_i, c_i, w_i, describing the four parameters of a segment, with meanings as stated above.

Output Format

Output one integer in a single line, representing the maximum total weight that can be obtained.

5
2 9 1 1
3 9 1 10
4 8 1 10
5 6 3 1
7 9 3 10
21
10
1 2 2 8
2 4 2 2
6 10 3 5
2 8 2 4
5 9 2 7
1 1 1 10
2 8 2 2
1 7 3 7
8 9 2 4
5 7 3 3
29

Hint

Sample Explanation

For sample 11, the selected segments are segments 1,2,31, 2, 3. They are all of the same type, and the total weight is 2121. It can be proven that this selection is optimal.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Score mm \le wiw_i \le cic_i \le Special Property
00 55 1616 1010 10910^9 None
11 2020 2×1032 \times 10^3 10410^4
22 10510^5 22
33 10910^9 A
44 3535 None
  • Special property A: There do not exist distinct positive integers i,ji, j such that li<ljrj<ril_i < l_j \leq r_j < r_i.

For all testdata, it is guaranteed that 1m1051 \leq m \leq 10^5, 1liri1091 \leq l_i \leq r_i \leq 10^9, 1ci1091 \leq c_i \leq 10^9, and 1wi1041 \leq w_i \leq 10^4.

Translated by ChatGPT 5