Leaky roof - MarisaOJ: Marisa Online Judge

Leaky roof

Time limit: 1000 ms
Memory limit: 256 MB
Marisa is facing a problem with her leaky roof at her house, which occurs whenever it rains. However, she has a collection of spare planks available, where each plank $i$ has the ability to cover a specific range from position $x_i$ to $y_i$ on the roof of size $L$. Over a period of $q$ rainy days, Marisa encounters different leak positions. On day $i$, the roof leaks within the range from position $l_i$ to $r_i$. The objective is to determine the minimum number of planks that Marisa needs to use in order to fix the roof, or alternatively, determine if it is impossible for her to fix the roof using the available planks. Planks can overlap. ### Input - The first line contains three integers $n, q, L$. - The next $n$ lines, each line contains two integers $x_i,y_i$. - The next $q$ lines, each line contains two integers $l_i,r_i$. ### Output - For each raining day, print the minimum number of planks Marisa has to use, or print `-1` if there is no way to fix the roof. ### Constraints - $1 \le n, q,L \le 10^5$. - $1 \le x \le y \le L$. - $1 \le l \le r \le L$. ### Example Input: ``` 2 2 4 1 3 2 3 1 4 2 3 ``` Output: ``` -1 1 ```
Topic
Data structure
Rating 1800
Solution (0) Solution