CF526F.Pudding Monsters
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
本题中,你将接触到游戏《布丁怪兽》(Pudding Monsters)的一个简化模型。
开发任何游戏的重要环节之一是关卡设计。《布丁怪兽》的游戏场地是一个 n×n 的矩形网格,其中 n 个格子中各有一个怪兽,其余一些格子中则放置了其他游戏对象。游戏玩法围绕着在场地上移动怪兽展开:当两个怪兽彼此相邻(即上下左右相接)时,它们会粘合为一个更大的怪兽(别忘了它们可是布丁做的!)。

统计表明,若初始状态下每行恰好有一个怪兽,且每列也恰好有一个怪兽,则生成的地图最具趣味性;其余地图特性则通过合理布置其他游戏对象来设定。
为提升开发效率,业界广泛采用资源复用技术。例如,若已有一个大型的 n×n 地图,你可在其中选取一个更小的 k×k 的正方形区域,该区域恰好包含 k 个布丁怪兽,并将其作为原地图的一个简化版本。
现在,请你计算:在初始地图中,有多少种方式可以选出一个 k×k(其中 1≤k≤n)的正方形子区域,使得该子区域恰好包含 k 个布丁怪兽?请输出该数目。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 3 × 105) — 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.
第一行包含一个整数 n(1≤n≤3×105)—— 初始场地的大小。
接下来的 n 行包含初始时有怪物的格子的坐标。其中第 i 行包含两个数 ri, ci(1≤ri, ci≤n)—— 表示第 i 个怪物初始所在的格子的行号与列号。
保证所有 ri 互不相同,且所有 ci 互不相同。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?