CF1810D Climbing the Tree
Description
The snails are climbing a tree. The tree height is $ h $ meters, and snails start at position $ 0 $ .
Each snail has two attributes $ a $ and $ b $ ( $ a > b $ ). Starting from the $ 1 $ -st day, one snail climbs the tree like this: during the daylight hours of the day, he climbs up $ a $ meters; during the night, the snail rests, and he slides down $ b $ meters. If on the $ n $ -th day, the snail reaches position $ h $ for the first time (that is, the top of the tree), he will finish climbing, and we say that the snail spends $ n $ days climbing the tree. Note that on the last day of climbing, the snail doesn't necessarily climb up $ a $ meters, in case his distance to the top is smaller than $ a $ .
Unfortunately, you don't know the exact tree height $ h $ at first, but you know that $ h $ is a positive integer. There are $ q $ events of two kinds.
- Event of type $ 1 $ : a snail with attributes $ a $ , $ b $ comes and claims that he spent $ n $ days climbing the tree. If this message contradicts previously adopted information (i. e. there is no tree for which all previously adopted statements and this one are true), ignore it. Otherwise, adopt it.
- Event of type $ 2 $ : a snail with attributes $ a $ , $ b $ comes and asks you how many days he will spend if he climbs the tree. You can only give the answer based on the information you have adopted so far. If you cannot determine the answer precisely, report that.
You need to deal with all the events in order.
Input Format
N/A
Output Format
N/A
Explanation/Hint
In the first test case, we can determine $ h=7 $ through the first message, so we know the second snail and the third snail need to spend $ 2 $ and $ 5 $ days respectively to reach the top.
Let's show how the second snail climbs:
- During the daylight hours of the $ 1 $ st day: climbs up $ 4 $ meters, now at position $ 4 $ .
- During the night of the $ 1 $ st day: slides down $ 1 $ meters, now at position $ 3 $ .
- During the daylight hours of the $ 2 $ nd day: climbs up $ 4 $ meters, now at position $ 7 $ (reaches the top).
In the third test case, the second snail's message contradicts the first snail's, because the second snail says he spent $ 3 $ days, and he can climb at most $ 1+1+2=4 $ meters in the first $ 3 $ days. However, the first snail only needs $ 1 $ day to climb $ 4 $ meters.