ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Ural FU Junior Championship 2016

About     Problems     Submit solution     Judge status     Standings
Contest is over

F. Alice and Bob are on Bikes

Time limit: 1.0 second
Memory limit: 64 MB
Alice and Bob, after played enough and completely figured out the game with colored strip, decided to ride bikes around the fountain on a circular path of length L. Alice rides with a speed vA, Bob — with a speed vB, and they have started in different directions. At the initial moment the kids were in the same point. When they “meet” (i.e., at some moment they are in the same point as in the previous were not), they joyfully exclaim (“Oh, Bob!” or “Oh, Alice!” respectively). But sometimes along the way, the kids stop to feed the squirrels. Find, how many times Alice and Bob “have met”.


The first line contains integers L, T, vA, and vB that are the length of the path, the riding time and the speed of Alice and Bob, respectively (1 ≤ L ≤ 109; 1 ≤ T ≤ 106; 1 ≤ vA,vB ≤ 103).
The next line contains a single integer n, that is the number of intervals in which children were feeding squirrels (0 ≤ n ≤ 105). The next n lines describe those intervals. Each description consists of three integers: typei ti di, meaning who was feeding (1 for Alice and 2 for Bob), at what moment the feeding started and how much time it lasted, respectively (0 ≤ ti, diT; ti + diT).
It is guaranteed that for one kid any two intervals intersect in no more than one point. The intervals are given in order of non-decreasing ti.


Output the number of “meetings” of Alice and Bob.


10 10 2 1
1 1 1
1 2 2
2 2 1
Problem Author: Nikita Sivukhin
Problem Source: Ural FU Junior Championship 2016
To submit the solution for this problem go to the Problem set: 2105. Alice and Bob are on Bikes