問題一覧 > 通常問題

No.1920 Territory

レベル : / AI推定難易度 : 2550 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 18
作問者 : とりゐ / テスター : るさ riano
お気に入りにしたユーザー ProblemId : 7947 / 自分の提出
問題文最終更新日: 2022-04-25 23:36:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 341 (順位表) の他の問題:

Problem Statement

The territory of the yuki Kingdom is divided into several regions by $N+M$ fences.

When the territory of the yuki Kingdom is viewed on the $xy$-plane, the fences are represented as line segments. The first $N$ fences are parallel to the $x$-axis. Among these, the $i$-th fence connects the points $(b_i,a_i)$ and $(c_i,a_i)$ with a straight line. The remaining $M$ fences are parallel to the $y$-axis. Among these, the $i$-th fence connects the points $(p_i,q_i)$ and $(p_i,r_i)$ with a straight line.

Find the number of regions (of finite area) into which the territory is divided by these fences.

Definition of a region (click to expand) Let $X$ be the set of points on the $xy$-plane that do not lie on any fence (line segment). For $2$ points $(a,b),(c,d)\in X$, define $(a,b)\sim(c,d)$ if there exists a curve connecting the $2$ points $(a,b),(c,d)$ that has no point in common with any fence (line segment); then $\sim$ is an equivalence relation on $X$. The classes obtained by classifying $X$ under this equivalence relation are called regions. See also the figures in the samples.
In this problem, you need to find the number of regions of finite area, so the answer is $|X/\sim|-1$.

Input

$N$ $M$
$a_1$ $b_1$ $c_1$
$a_2$ $b_2$ $c_2$
$\vdots$
$a_N$ $b_N$ $c_N$
$p_1$ $q_1$ $r_1$
$p_2$ $q_2$ $r_2$
$\vdots$
$p_M$ $q_M$ $r_M$

  • $1\leq N,M\leq 10^5$
  • $1\leq a_i,b_i,c_i\leq 2\times 10^5$
  • $1\leq p_i,q_i,r_i\leq 2\times 10^5$
  • $a_i\neq a_j\ (i\neq j)$
  • $b_i\lt c_i$
  • $p_i\neq p_j\ (i\neq j)$
  • $q_i\lt r_i$
  • All input values are integers.

Output

Output the number of regions.

Sample

Sample 1
Input
4 4
1 1 3
2 1 3
3 2 4
4 1 4
1 1 3
2 1 3
3 1 4
4 1 4
Output
4

The territory is divided into $4$ regions as shown below.

Sample 2
Input
12 12
1 1 4
2 2 3
3 2 3
4 1 4
5 5 8
6 6 7
7 6 8
8 5 8
9 9 12
10 9 11
11 10 12
12 9 12
1 1 4
2 2 3
3 2 3
4 1 4
5 5 8
6 6 7
7 6 7
8 5 8
9 9 12
10 10 11
11 10 11
12 9 12
Output
7

The territory is divided into $7$ regions as shown below.

Sample 3
Input
4 5
1 2 5
2 3 4
4 2 4
5 1 5
1 1 5
2 1 4
3 2 3
4 2 4
5 1 5
Output
0

The territory is divided into $0$ regions as shown below.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。