Minimal Segment Cover
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
You are given intervals in form on a number line.
You are also given queries in form . What is the minimal number of intervals you have to take so that every point (not necessarily integer) from to is covered by at least one of them?
If you can't choose intervals so that every point from to is covered, then print -1 for that query.
The first line contains two integers and () — the number of intervals and the number of queries, respectively.
Each of the next lines contains two integer numbers and () — the given intervals.
Each of the next lines contains two integer numbers and () — the queries.
Print integer numbers. The -th number should be the answer to the -th query: either the minimal number of intervals you have to take so that every point (not necessarily integer) from to is covered by at least one of them or -1 if you can't choose intervals so that every point from to is covered.
Input
The first line contains two integers and () — the number of intervals and the number of queries, respectively.
Each of the next lines contains two integer numbers and () — the given intervals.
Each of the next lines contains two integer numbers and () — the queries.
Output
Print integer numbers. The -th number should be the answer to the -th query: either the minimal number of intervals you have to take so that every point (not necessarily integer) from to is covered by at least one of them or -1 if you can't choose intervals so that every point from to is covered.
Note
In the first example there are three queries:
- query can be covered by interval ;
- query can be covered by intervals and . There is no way to cover by a single interval;
- query can be covered by interval . It doesn't matter that the other points are covered besides the given query.
In the second example there are four queries:
- query can be covered by interval . Note that you can choose any of the two given intervals ;
- query can be covered by interval ;
- query can't be covered by any set of intervals;
- query can't be covered by any set of intervals. Note that intervals and together don't cover because even non-integer points should be covered. Here , for example, isn't covered.
20240326集训
- Status
- Done
- Rule
- IOI
- Problem
- 7
- Start at
- 2024-3-26 19:00
- End at
- 2024-3-26 21:00
- Duration
- 2 hour(s)
- Host
- Partic.
- 14