luogu#P5029. T'ill It's Over
T'ill It's Over
Background
The little square was crushed into dust by the Lord of Darkness.
Is everything really over like this?
Just when everyone thought there was no hope of turning the tables,
parts of the two World Trees that had already been purified began to flicker faintly……
Problem Description
The little square has been revived by the power of the triangle, and it is about to start the final battle with the Lord of Darkness.
The little square’s final goal is to purify the Lord of Darkness.
The Lord of Darkness has a centipede body of length , and at the beginning the brightness level of each segment is .
When the brightness level of a segment reaches a specified value (), we consider this segment to be purified.
To purify the Lord of Darkness, the little square has prepared types of plans. By their essential differences, these plans can be roughly divided into four types:
-
Change the brightness level of a segment with brightness level to . (Note that may be .)
-
Change the brightness level of a segment whose brightness level is in the interval from to to .
-
Change the brightness level of a segment with brightness level to any value in the interval from to .
-
Change the brightness level of a segment whose brightness level is in the interval from to to any value in the interval from to .
Since using each plan consumes a certain amount of attribute energy, each plan has its own independent upper limit on the number of uses. In one plan, we use to denote this upper limit.
The little square wants to know the maximum number of segments of the Lord of Darkness’s centipede that can be purified.
Input Format
The first line contains three positive integers , representing the length of the Lord of Darkness’s centipede body, the total number of plans, and the described above.
The next lines each start with two positive integers , representing the type of the plan and the upper limit on the number of uses. The input for each plan type is as follows:
If , then two integers follow, with the meaning described above.
If , then three integers follow, with the meaning described above.
If , then three integers follow, with the meaning described above.
If , then four integers follow, with the meaning described above.
The data guarantees that all .
Output Format
Output one integer in a single line, representing the maximum number of segments that can be purified.
5 4 5
1 3 1 3
1 3 3 2
1 3 2 5
4 1 1 1 4 5
4
Hint
First use plans 1, 2, and 3 to change the brightness levels of three segments to , then change them to , and then to .
Then use plan 4 to change the brightness level of one segment to .
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, .
For the first of the testdata, the time limit is ms.
For of the testdata, $n \le 10^7, m \le 20000, 1 \le k \le 10^5, 1 \le l \le 10^5$.
For the last of the testdata, the time limit is ms.
The data guarantees that the operations are randomly generated.
Translated by ChatGPT 5