A9820 | Cubes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Once Vasya and Petya assembled a figure of $m$ cubes, each of them is associated with a number between $0$ and $m-1$ (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the $OX$ is the ground, and the $OY$ is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.
The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates $(x,y)$ either $y=0$ , or there is a cube with coordinates $(x-1,y-1)$ , $(x,y-1)$ or $(x+1,y-1)$ .
Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the $m$ -ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.
Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo $10^{9}+9$ .
The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates $(x,y)$ either $y=0$ , or there is a cube with coordinates $(x-1,y-1)$ , $(x,y-1)$ or $(x+1,y-1)$ .
Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the $m$ -ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.
Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo $10^{9}+9$ .
输入格式
The first line contains number $m$ ( $2<=m<=10^{5}$ ).
The following $m$ lines contain the coordinates of the cubes $x_{i},y_{i}$ ( $-10^{9}<=x_{i}<=10^{9}$ , $0<=y_{i}<=10^{9}$ ) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.
No two cubes occupy the same place.
The following $m$ lines contain the coordinates of the cubes $x_{i},y_{i}$ ( $-10^{9}<=x_{i}<=10^{9}$ , $0<=y_{i}<=10^{9}$ ) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.
No two cubes occupy the same place.
输出格式
In the only line print the answer to the problem.
输入输出样例
输入 #1
3 2 1 1 0 0 1
输出 #1
19
输入 #2
5 0 0 0 1 0 2 0 3 0 4
输出 #2
2930
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted