#P9094. Mixing Colors
Mixing Colors
Mixing Colors
Byteasar is planning to paint his fence, but he does not want the fence to be painted white. He has n pots of white paint arranged in a row, numbered from 1 to n. A color mixing expert has carried out m operations. In the i-th operation, the expert adds one of three pigments — yellow, blue, or red — to each pot from li to ri (inclusive).
The final color of a paint pot depends on the set of pigments added to it. The color mixtures are determined according to the following table:
Pigments | Color |
---|---|
None | White |
Yellow | Yellow |
Blue | Blue |
Red | Red |
Yellow + Blue | Green |
Yellow + Red | Orange |
Blue + Red | Purple |
Yellow + Blue + Red | Brown |
Byteasar has chosen green because it symbolizes the 'Accepted' verdict typical in programming contests. Help him determine how many pots of paint have become green. A pot is green if it has received both yellow and blue pigments, and no red pigment.
Note: If a pigment is added multiple times to a pot, it is counted only once. In other words, only the set of pigments matters.
inputFormat
The first line contains two integers n and m, where 1 ≤ n ≤ 105 and 0 ≤ m ≤ 105. The next m lines each contain an operation described by two integers l and r (1 ≤ l ≤ r ≤ n) and a character representing the pigment ('Y' for yellow, 'B' for blue, 'R' for red), separated by spaces.
If m is 0, no further input follows.
outputFormat
Output a single integer — the number of pots that are green after performing all operations.
sample
5 3
1 3 Y
2 5 B
4 5 R
2