A9794 | Pudding Monsters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In this problem you will meet the simplified model of game Pudding Monsters.
An important process in developing any game is creating levels. A game field in Pudding Monsters is an $n×n$ rectangular grid, $n$ of its cells contain monsters and some other cells contain game objects. The gameplay is about moving the monsters around the field. When two monsters are touching each other, they glue together into a single big one (as they are from pudding, remember?).
Statistics showed that the most interesting maps appear if initially each row and each column contains exactly one monster and the rest of map specifics is set up by the correct positioning of the other game objects.
A technique that's widely used to make the development process more efficient is reusing the available resources. For example, if there is a large $n×n$ map, you can choose in it a smaller $k×k$ square part, containing exactly $k$ monsters and suggest it as a simplified version of the original map.
You wonder how many ways there are to choose in the initial map a $k×k$ ( $1<=k<=n$ ) square fragment, containing exactly $k$ pudding monsters. Calculate this number.
An important process in developing any game is creating levels. A game field in Pudding Monsters is an $n×n$ rectangular grid, $n$ of its cells contain monsters and some other cells contain game objects. The gameplay is about moving the monsters around the field. When two monsters are touching each other, they glue together into a single big one (as they are from pudding, remember?).
Statistics showed that the most interesting maps appear if initially each row and each column contains exactly one monster and the rest of map specifics is set up by the correct positioning of the other game objects.
A technique that's widely used to make the development process more efficient is reusing the available resources. For example, if there is a large $n×n$ map, you can choose in it a smaller $k×k$ square part, containing exactly $k$ monsters and suggest it as a simplified version of the original map.
You wonder how many ways there are to choose in the initial map a $k×k$ ( $1<=k<=n$ ) square fragment, containing exactly $k$ pudding monsters. Calculate this number.
输入格式
The first line contains a single integer $n$ ( $1<=n<=3×10^{5}$ ) — the size of the initial field.
Next $n$ lines contain the coordinates of the cells initially containing monsters. The $i$ -th of the next lines contains two numbers $r_{i},c_{i}$ ( $1<=r_{i},c_{i}<=n$ ) — the row number and the column number of the cell that initially contains the $i$ -th monster.
It is guaranteed that all $r_{i}$ are distinct numbers and all $c_{i}$ are distinct numbers.
Next $n$ lines contain the coordinates of the cells initially containing monsters. The $i$ -th of the next lines contains two numbers $r_{i},c_{i}$ ( $1<=r_{i},c_{i}<=n$ ) — the row number and the column number of the cell that initially contains the $i$ -th monster.
It is guaranteed that all $r_{i}$ are distinct numbers and all $c_{i}$ are distinct numbers.
输出格式
Print the number of distinct square fragments of the original field that can form a new map.
输入输出样例
输入 #1
5 1 1 4 3 3 2 2 4 5 5
输出 #1
10
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted