A13721 | Divide Square
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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 $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 < y_i < 10^6$ ; $0 \le lx_i < 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 < x_i < 10^6$ ; $0 \le ly_i < 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.
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 < y_i < 10^6$ ; $0 \le lx_i < 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 < x_i < 10^6$ ; $0 \le ly_i < 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.
输出格式
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:


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted