Typhoon
Time limit2sMemory limit1024 MB
Each typhoon covers a contiguous range of observation points; for each query, count how many typhoons in a given index range cover a given point.
- Level
Medium7 of 10
- Topics
- Prefix sum, Sorting, Binary search, Array
- Solved
- No attempts yet
Problem
There is a straight road that is prone to damage from typhoons. On this road, the damage from a typhoon is always a single contiguous segment. Along the road there are observation points, numbered to in order starting from the point closest to one end of the road.
There are records of typhoons that damaged this road. The record for typhoon is stored as the number of the lowest-numbered observation point damaged by typhoon and the number of the highest-numbered observation point damaged by typhoon . Typhoons are numbered to in order from oldest to newest.
Recently it was discovered that studying typhoon damage on this road leads to a major advance in meteorology, and to carry out the research, pieces of information of the form "how many of the typhoons numbered through damaged observation point " became necessary.
Given the typhoon records and the pairs of an observation point and a range of typhoon numbers for which information is needed to carry out the research (hereafter called queries), write a program that outputs, for each query, the number of typhoons that dealt damage.
Input
The first line of the input contains three integers , , separated by spaces. These mean that the number of typhoons in the records is , the number of queries given is , and the number of observation points is . They satisfy and .
Line () contains two integers , separated by spaces. These mean that the lowest-numbered observation point damaged by typhoon is and the highest-numbered observation point damaged by typhoon is . They satisfy .
Line () contains three integers , , separated by spaces. These mean that the -th query has point number and typhoon number range from to . They satisfy and .
Output
Output to standard output. For each query, output the number of typhoons that dealt damage, in the given order, separated by newlines. That is, on line (), output a single integer representing how many of the typhoons numbered through damaged observation point .