HŽ
InterviewTime limit1sMemory limit1024 MB
Count the tickets whose route crosses a closed section, the fewest sections to reopen so no ticket needs a bus, and the longest run of stations with no closure.
- Level
Easy3 of 10
- Topics
- Intervals, Prefix sum
- Solved
- No attempts yet
Problem
A railway line has stations numbered from 1 to . For maintenance, sections of the track are closed. No trains run in either direction on a closed section, and passengers travel through those sections by bus. Each closed section is given by its start station and its end station.
Consider this situation. A passenger arrives at station and buys a ticket to station . If any part of the route between and is traveled by bus, the ticket must say so. There are such situations to study.
Answer the following questions:
- On how many of the tickets is it written that some or all of the route is traveled by bus?
- What is the minimum number of the sections that must be reopened so that none of the tickets has a bus warning?
- What is the length, in number of stations, of the longest stretch of the line that can be traveled only by train?
Input
The first line contains a natural number ().
The second line contains a natural number ().
Each of the next lines contains two natural numbers and (, , ), the start and end stations of the -th closed section. The closed sections do not overlap.
The next line contains a natural number ().
Each of the next lines contains two natural numbers and (, , ), the stations for the -th situation.
Output
On the first line, print the answer to the first question.
On the second line, print the answer to the second question.
On the third line, print the answer to the third question.
Hint
In the first sample, the work on the section from station 8 to station 11 means that the first, second, and fourth passengers get a bus warning on their tickets. If that section were reopened, all passengers would travel by train only. The longest stretch with no work runs from station 11 to station 18 (or from station 1 to station 8), with a length of 8 stations.