Rainfall
Time limit2sMemory limit128 MB
Given partial yearly rainfall records, decide for each query whether a claimed record-rain statement between two years is definitely true, possibly true, or impossible.
- Level
Medium7 of 10
- Topics
- Binary search, Array, Greedy
- Solved
- No attempts yet
Problem
For each year, the officially measured amount of rain is called that year's rainfall. Based on these records, people may say, “In year X, the rainfall was the greatest since year Y.” Some yearly records may be missing, so you must decide whether each statement is certainly true, only possible, or impossible.
The statement “In year X, the rainfall was the greatest since year Y” is true when all of the following conditions hold.
- The rainfall is known for every year from Y through X.
- The rainfall in year X is less than or equal to the rainfall in year Y.
- For every year Z such that Y < Z < X, the rainfall in year Z is less than the rainfall in year X.
If the missing yearly rainfall values can be chosen so that the conditions hold, the answer is maybe. If the known information already makes the conditions impossible, the answer is false. If every condition is fully verified, the answer is true.
Input
The first line contains an integer n (1 <= n <= 50,000).
Each of the next n lines contains two integers y and r, meaning that the rainfall in year y is r.
- 0 <= |y| <= 1,000,000,000
- 1 <= r <= 1,000,000,000
The rainfall records are given in increasing order of y.
The next line contains an integer m (1 <= m <= 10,000).
Each of the next m lines contains two integers Y and X, representing the statement “In year X, the rainfall was the greatest since year Y.”
- -1,000,000,000 <= Y < X <= 1,000,000,000
Output
For each statement, print one answer on its own line.
- Print
trueif the statement is certainly true. - Print
maybeif it could be true but cannot be confirmed. - Print
falseif it is impossible.