CF1401E.Divide Square

普及/提高-

通过率:0%

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.

输入格式

The first line contains two integers nn and mm ( 0n,m1050 \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 < y_i < 10^6 ; 0lxi<rxi1060 \le lx_i < 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 < x_i < 10^6 ; 0lyi<ryi1060 \le ly_i < 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.

输出格式

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:

首页