| SLPC 2024 Open Division |
|---|
| Закончено |
Womais is taking a road trip through the fictional country of Muigleb. Unfortunately, he is late to his destination and would like to shave some time off his trip – but he is also scared of speeding and getting caught by the vigilant Muiglebian police. Highways in Muigleb have two lanes: the left lane and the right lane. Everybody in the right lane drives at the speed of 100 km/h, which is the Muiglebian speed limit. Cars in the left lane may drive at arbitrary speeds (even above the speed limit), subject to the following constraint: no car can drive faster than the car in front of it. Every car $$$c$$$ driving in the left lane will have an internal speed preference $$$s_c$$$. Then, if a car is driving in the left lane, its speed at any given moment will be equal to $$$\min(s_c, v)$$$, where $$$v$$$ is the speed of the car in front of it or $$$+\infty$$$ if there is no such car. To drive quickly and avoid getting pulled over, Womais will drive according to the following algorithm:
The first line of the input will contain two positive integers $$$d, n$$$ ($$$1 \leq d \leq {10}^9$$$, $$$0 \leq n \leq 2\cdot {10}^5$$$) – the length of the road trip in kilometers and the number of events to follow.
The $$$i$$$-th of the following $$$n$$$ lines will contain two positive integers $$$t_i, m_i$$$ ($$$1 \leq t_i, m_i \leq {10}^9$$$) and a character $$$c_i \in \{\texttt{L}, \texttt{R}\}$$$. If $$$c_i$$$ is $$$\texttt{L}$$$, the line will also contain a positive integer $$$s_i$$$ ($$$1 \leq s_i \leq {10}^9$$$). Here $$$t_i$$$ is the time in seconds of the $$$i$$$-th event (Womais's journey starts at time 0), $$$m_i$$$ is the unique identifier of the car involved in event $$$i$$$. The two cases for $$$c_i$$$ are as follows:
It is guaranteed that $$$t_i$$$ are strictly increasing.
The only line of output should contain a single integer, which is the number of seconds it will take Womais to drive $$$d$$$ km from the start of his journey, rounded up.
1000 310000 1 L 15015000 2 L 12520000 2 R
28167
In sample case 1, Womais is driving in the right lane with the speed of 100 km/h for the first 10000 seconds. At 10000s car 1 switches from right to left and Womais switches behind it, both of them driving at 150 km/h. At 15000s car 2 switches to the left in front of car 1, and both car 1 and Womais slow down to 125 km/h. At 20000s car 2 goes back to the right lane, and car 1 and Womais both speed back up to 150 km/h.
| Название |
|---|


