#DP1038. Minimal Segment Cover
Minimal Segment Cover
Minimal Segment Cover
题面翻译
- 给定 个线段,每个线段形如 。
- 次询问,每次询问给出 ,求至少选多少个线段才能使这些线段的并能包含线段 。
- ,,。
题目描述
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.
样例 #1
样例输入 #1
2 3
1 3
2 4
1 3
1 4
3 4
样例输出 #1
1
2
1
样例 #2
样例输入 #2
3 4
1 3
1 3
4 5
1 2
1 3
1 4
1 5
样例输出 #2
1
1
-1
-1
提示
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.