QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 2048 MB Total points: 100

#7675. 監視

Statistics

International Corporation for Protection and Control(ICPC)は、そう、保護と制御のための効率的な技術を開発しています。当然、自社の本社も保護し、管理したいと考えています。上から見ると、本社の建物は凸多角形の形をしています。その周囲には、建物を監視するカメラを設置するのに適した場所がいくつかあります。各カメラは、設置場所に応じて多角形の辺(建物の壁)のある範囲を監視します。ICPC は、建物全体を監視するために必要なカメラの台数を最小にしたいと考えています。

入力

入力は単一のテストケースからなります。最初の行には $2$ つの整数 $n$ と $k$($3 \le n \le 10^6$ かつ $1 \le k \le 10^6$)が与えられます。$n$ は壁の数、$k$ はカメラを設置できる場所の数です。続く $k$ 行には、それぞれ $2$ つの整数 $a_i$ と $b_i$($1 \le a_i, b_i \le n$)が与えられます。これらの整数は、$i$ 番目の場所のカメラが監視する壁を指定します。$a_i \le b_i$ の場合、そのカメラは $a_i \le j \le b_i$ を満たすすべての壁 $j$ を監視します。$a_i > b_i$ の場合、そのカメラは $a_i \le j \le n$ または $1 \le j \le b_i$ を満たすすべての壁 $j$ を監視します。

出力

建物のすべての壁を監視するのに十分なカメラの最小台数を出力してください。$2$ 台のカメラが監視する範囲は重なってもかまいません。建物全体を監視できない場合は、代わりに impossible を出力してください。

入出力例

入力 1

100 7
1 50
50 70
70 90
90 40
20 60
60 80
80 20

出力 1

3

入力 2

8 2
8 3
5 7

出力 2

impossible

入力 3

8 2
8 4
5 7

出力 3

2

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.