#P9094. [PA 2020] Mieszanie kolorów

[PA 2020] Mieszanie kolorów

Problem Description

This problem is translated from PA 2020 Round 1 Mieszanie kolorów.

Byteasar is getting ready to paint a fence. He has prepared nn cans of white paint, arranged in a row and numbered from 11 to nn. He wants to use these paints, but he does not want to paint the fence white. He hired a color-mixing expert who has three pigments: yellow, blue, and red. The expert performs mm operations; in the ii-th operation, a certain pigment is added to all cans with indices from lil_i to rir_i (inclusive).

The final color of a paint can depends on which pigments have been added to it. The pigments are mixed according to the following table and illustration.

Pigment Color
None White
Yellow
Blue
Red
Yellow + Blue Green
Yellow + Red Orange
Blue + Red Purple
Yellow + Blue + Red Brown

Byteasar wants to paint the fence a single color. After thinking it over, he chose green, because green stands for the Accepted result you often see in programming contests. He wants to know how many cans of paint are green now. Please help him count them.

Input Format

The first line contains two integers n,mn, m, representing the number of paint cans and the number of operations performed by the expert.

The next mm lines each contain three integers li,ri,kil_i, r_i, k_i, meaning that in the ii-th operation, a pigment is added to all cans with indices from lil_i to rir_i (inclusive). The added pigment is yellow (ki=1k_i = 1), blue (ki=2k_i = 2), or red (ki=3k_i = 3).

Output Format

Output one integer on a single line, the number of cans that are green after all operations.

9 5
2 8 1
4 5 2
6 7 3
5 6 2
1 2 2
3

Hint

Explanation of Sample 1

After the operations, the paints are blue, green, yellow, green, green, brown, orange, yellow, and white. Therefore, only three cans of paint are green.


Constraints

This problem uses bundled testdata.

For 100%100\% of the data, it is guaranteed that 1n,m1061 \le n, m \le 10^6, 1lirin1 \le l_i \le r_i \le n, and 1ki31 \le k_i \le 3.

Translated by ChatGPT 5