Codeforces Round 665 (Div. 2)
E
Divide Square
Codeforces
2400
原题
← DF →
翻译中…

There is a square of size $10^6 \times 10^6$ on the coordinate plane with four points $(0, 0)$, $(0, 10^6)$, $(10^6, 0)$, and $(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.

翻译中…

Input

翻译中…

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

翻译中…

The next $n$ lines contain descriptions of the horizontal segments. The $i$-th line contains three integers $y_i$, $lx_i$ and $rx_i$ ($0 \lt y_i \lt 10^6$; $0 \le lx_i \lt rx_i \le 10^6$), which means the segment connects $(lx_i, y_i)$ and $(rx_i, y_i)$.

翻译中…

The next $m$ lines contain descriptions of the vertical segments. The $i$-th line contains three integers $x_i$, $ly_i$ and $ry_i$ ($0 \lt x_i \lt 10^6$; $0 \le ly_i \lt ry_i \le 10^6$), which means the segment connects $(x_i, ly_i)$ and $(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.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

The sample is like this:

翻译中…

image

翻译中…

样例

Input #1
3 3
2 3 1000000
4 0 4
3 0 1000000
4 0 1
2 0 5
3 1 1000000
Output #1
7
InputCopy OutputCopy
题目信息
题号
1401E
时间限制
2 s
内存限制
384 MB
标签
数据结构
计算几何
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。