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 nn, and at the beginning the brightness level of each segment is 11.

When the brightness level of a segment reaches a specified value (kk), we consider this segment to be purified.

To purify the Lord of Darkness, the little square has prepared mm types of plans. By their essential differences, these plans can be roughly divided into four types:

  1. Change the brightness level of a segment with brightness level aa to bb. (Note that bb may be a\le a.)

  2. Change the brightness level of a segment whose brightness level is in the interval from a1a1 to a2a2 to b1b1.

  3. Change the brightness level of a segment with brightness level a1a1 to any value in the interval from b1b1 to b2b2.

  4. Change the brightness level of a segment whose brightness level is in the interval from a1a1 to a2a2 to any value in the interval from b1b1 to b2b2.

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 ll 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 n,m,kn, m, k, representing the length of the Lord of Darkness’s centipede body, the total number of plans, and the kk described above.

The next mm lines each start with two positive integers op,lop, l, 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 op=1op = 1, then two integers a,ba, b follow, with the meaning described above.

If op=2op = 2, then three integers a1,a2,b1a1, a2, b1 follow, with the meaning described above.

If op=3op = 3, then three integers a1,b1,b2a1, b1, b2 follow, with the meaning described above.

If op=4op = 4, then four integers a1,a2,b1,b2a1, a2, b1, b2 follow, with the meaning described above.

The data guarantees that all 1a,b,a1,b1,a2,b2k1 \le a, b, a1, b1, a2, b2 \le k.

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 33, then change them to 22, and then to 55.

Then use plan 4 to change the brightness level of one segment to 55.

For 10%10\% of the testdata, n=1,op=1n = 1, op = 1.

For another 10%10\% of the testdata, n=1,op3n = 1, op \le 3.

For another 10%10\% of the testdata, n10,op=1n \le 10, op = 1.

For another 20%20\% of the testdata, n100,m100,op=1n \le 100, m \le 100, op = 1.

For 70%70\% of the testdata, n1000,m1000,op3,k20000n \le 1000, m \le 1000, op \le 3, k \le 20000.

For the first 70%70\% of the testdata, the time limit is 500500 ms.

For 100%100\% 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 30%30\% of the testdata, the time limit is 80008000 ms.

The data guarantees that the operations are randomly generated.

Translated by ChatGPT 5