CF1401E.Divide Square

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:384MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a square of size 106×10610^6 \times 10^6 on the coordinate plane with four points (0,0)(0, 0), (0,106)(0, 10^6), (106,0)(10^6, 0), and (106,106)(10^6, 10^6) as its vertices.

You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square.

Now you are wondering how many pieces this square divides into after drawing all segments. Write a program calculating the number of pieces of the square.

在坐标平面上有一个边长为 106×10610^6 \times 10^6 的正方形,其四个顶点分别为 (0,0)(0, 0)、(0,106)(0, 10^6)、(106,0)(10^6, 0) 和 (106,106)(10^6, 10^6)。

你将在该平面上绘制若干线段。所有线段均为水平或垂直方向,且每条线段至少与正方形的一条边相交。

现在你想知道:在绘制完所有线段后,该正方形被分成了多少个区域?请编写一个程序计算正方形被分割出的区域数量。

输入格式

The first line contains two integers nn and mm (0≤n,m≤1050 \le n, m \le 10^5) — the number of horizontal segments and the number of vertical segments.

The next nn lines contain descriptions of the horizontal segments. The ii-th line contains three integers yiy_i, lxilx_i and rxirx_i (0<yi<1060 \lt y_i \lt 10^6; 0≤lxi<rxi≤1060 \le lx_i \lt rx_i \le 10^6), which means the segment connects (lxi,yi)(lx_i, y_i) and (rxi,yi)(rx_i, y_i).

The next mm lines contain descriptions of the vertical segments. The ii-th line contains three integers xix_i, lyily_i and ryiry_i (0<xi<1060 \lt x_i \lt 10^6; 0≤lyi<ryi≤1060 \le ly_i \lt ry_i \le 10^6), which means the segment connects (xi,lyi)(x_i, ly_i) and (xi,ryi)(x_i, ry_i).

It's guaranteed that there are no two segments on the same line, and each segment intersects with at least one of square's sides.

第一行包含两个整数 nn 和 mm(0≤n,m≤1050 \le n, m \le 10^5),分别表示水平线段的数量和垂直线段的数量。

接下来的 nn 行描述水平线段。第 ii 行包含三个整数 yiy_i、lxilx_i 和 rxirx_i(0<yi<1060 \lt y_i \lt 10^6;0≤lxi<rxi≤1060 \le lx_i \lt rx_i \le 10^6),表示该线段连接点 (lxi,yi)(lx_i, y_i) 和 (rxi,yi)(rx_i, y_i)。

接下来的 mm 行描述垂直线段。第 ii 行包含三个整数 xix_i、lyily_i 和 ryiry_i(0<xi<1060 \lt x_i \lt 10^6;0≤lyi<ryi≤1060 \le ly_i \lt ry_i \le 10^6),表示该线段连接点 (xi,lyi)(x_i, ly_i) 和 (xi,ryi)(x_i, ry_i)。

保证不存在两条线段位于同一条直线上,且每条线段至少与正方形的一条边相交。

输出格式

Print the number of pieces the square is divided into after drawing all the segments.

画出所有线段后,输出正方形被分割成的块数。

输入输出样例

  • 输入#1

    3 3
    2 3 1000000
    4 0 4
    3 0 1000000
    4 0 1
    2 0 5
    3 1 1000000

    输出#1

    7

说明/提示

The sample is like this:

示例图如下:

输入解题思路,AI测评打分。不知道怎么写?

首页