QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#16897. 共通部分を作る

الإحصائيات

区間 $[l, r]$ とは、$l$ 以上 $r$ 以下のすべての実数からなる集合を意味する。

$N$ 個の区間が与えられる。このとき、以下の $Q$ 個のクエリを処理するプログラムを作成せよ。

  • 与えられた $l$ と $r$ に対して、1つ以上の区間を選択し、それらの共通部分が正確に $[l, r]$ となるようにできるか?もし可能であれば、最小で何個の区間を選択する必要があるか?

入力

1行目には区間の個数 $N$ が与えられる。($1 \le N \le 300\,000$)

続く $N$ 行には、各区間 $[l_i, r_i]$ を表す整数 $l_i$ と $r_i$ が空白区切りで与えられる。($0 \le l_i < r_i \le 10^6$)

続く行にはクエリの個数 $Q$ が与えられる。($1 \le Q \le 300\,000$)

続く $Q$ 行には、各クエリで与えられる2つの整数 $l$ と $r$ が空白区切りで与えられる。($0 \le l < r \le 10^6$)

出力

各クエリについて、区間の共通部分が正確に $[l, r]$ となるようにできない場合は $-1$ を出力し、できる場合は選択すべき区間の最小個数を出力せよ。

入出力例

入力 1

3
0 10
2 6
4 8
3
4 6
2 8
1 9

出力 1

2
-1
-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.