A937 | Sprinklers--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John has a large field, and he is thinking of planting sweet corn in
some part of it. After surveying his field, FJ found that it forms an $(N-1)
\times (N-1)$ square. The southwest corner is at coordinates $(0,0)$, and the
northeast corner is at $(N-1,N-1)$.
At some integer coordinates there are double-headed sprinklers, each one
sprinkling both water and fertilizer. A double-heading sprinkler at
coordinates $(i,j)$ sprinkles water on the part of the field north and east of
it, and sprinkles fertilizer on the part of the field south and west of it.
Formally, it waters all real coordinates $(x,y)$ for which $N \geq x \geq i$
and $N \geq y \geq j$, and it fertilizes all real coordinates $(x,y)$ for
which $0 \leq x \leq i$ and $0 \leq y \leq j$.
Farmer John wants to plant sweet corn in some axis-aligned rectangle in his
field with integer-valued corner coordinates. However, for the sweet corn to
grow, all points in the rectangle must be both watered and fertilized by the
double-headed sprinklers. And of course the rectangle must have positive area,
or Farmer John wouldn't be able to grow any corn in it!
Help Farmer John determine the number of rectangles of positive area in which
he could grow sweet corn. Since this number may be large, output the remainder
of this number modulo $10^9 + 7$.
some part of it. After surveying his field, FJ found that it forms an $(N-1)
\times (N-1)$ square. The southwest corner is at coordinates $(0,0)$, and the
northeast corner is at $(N-1,N-1)$.
At some integer coordinates there are double-headed sprinklers, each one
sprinkling both water and fertilizer. A double-heading sprinkler at
coordinates $(i,j)$ sprinkles water on the part of the field north and east of
it, and sprinkles fertilizer on the part of the field south and west of it.
Formally, it waters all real coordinates $(x,y)$ for which $N \geq x \geq i$
and $N \geq y \geq j$, and it fertilizes all real coordinates $(x,y)$ for
which $0 \leq x \leq i$ and $0 \leq y \leq j$.
Farmer John wants to plant sweet corn in some axis-aligned rectangle in his
field with integer-valued corner coordinates. However, for the sweet corn to
grow, all points in the rectangle must be both watered and fertilized by the
double-headed sprinklers. And of course the rectangle must have positive area,
or Farmer John wouldn't be able to grow any corn in it!
Help Farmer John determine the number of rectangles of positive area in which
he could grow sweet corn. Since this number may be large, output the remainder
of this number modulo $10^9 + 7$.
输入格式
The first line of the input consists of a single integer $N$, the size of the
field ($1 \leq N \leq 10^5$).
The next $N$ lines each contain two space-separated integers. If these
integers are $i$ and $j$, where $0 \leq i,j \leq N-1$, they denote a sprinkler
located at $(i,j)$.
It is guaranteed that there is exactly one sprinkler in each column and
exactly one sprinkler in each row. That is, no two sprinklers have the same
$x$-coordinate, and no two sprinklers have the same $y$-coordinate.
field ($1 \leq N \leq 10^5$).
The next $N$ lines each contain two space-separated integers. If these
integers are $i$ and $j$, where $0 \leq i,j \leq N-1$, they denote a sprinkler
located at $(i,j)$.
It is guaranteed that there is exactly one sprinkler in each column and
exactly one sprinkler in each row. That is, no two sprinklers have the same
$x$-coordinate, and no two sprinklers have the same $y$-coordinate.
输出格式
The output should consist of a single integer: the number of rectangles of
positive area which are fully watered and fully fertilized, modulo $10^9 + 7$.
positive area which are fully watered and fully fertilized, modulo $10^9 + 7$.
输入输出样例
输入 #1
5 0 4 1 1 2 2 3 0 4 3
输出 #1
21
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted