A837 | Falling Portals--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
There are $N$ ($2\le N\le 2\cdot 10^5$) worlds, each with a portal. Initially,
world $i$ (for $1 \leq i \leq N$) is at $x$-coordinate $i$, and $y$-coordinate
$A_i$ ($1\le A_i\le 10^9$). There is also a cow on each world. At time $0$,
all $y$-coordinates are distinct and the worlds start falling: world $i$ moves
continuously in the negative-$y$ direction at a speed of $i$ units per second.
At any time when two worlds are at the same $y$-coordinate (possibly a
fractional time), the portals "align", meaning that a cow on one of the worlds
can choose to travel instantaneously to the other world.
For each $i$, the cow on world $i$ wants to travel to world $Q_i$ ($Q_i\neq
i$). Help each cow determine how long her journey will take, if she travels
optimally.
Each query output should be a fraction $a/b$ where $a$ and $b$ are positive
and relatively prime integers, or $-1$ if it the journey is impossible.
world $i$ (for $1 \leq i \leq N$) is at $x$-coordinate $i$, and $y$-coordinate
$A_i$ ($1\le A_i\le 10^9$). There is also a cow on each world. At time $0$,
all $y$-coordinates are distinct and the worlds start falling: world $i$ moves
continuously in the negative-$y$ direction at a speed of $i$ units per second.
At any time when two worlds are at the same $y$-coordinate (possibly a
fractional time), the portals "align", meaning that a cow on one of the worlds
can choose to travel instantaneously to the other world.
For each $i$, the cow on world $i$ wants to travel to world $Q_i$ ($Q_i\neq
i$). Help each cow determine how long her journey will take, if she travels
optimally.
Each query output should be a fraction $a/b$ where $a$ and $b$ are positive
and relatively prime integers, or $-1$ if it the journey is impossible.
输入格式
* Test cases 2-3 satisfy $N\le 100.$
* Test cases 4-5 satisfy $N\le 2000.$
* Test cases 6-14 satisfy no additional constraints.
* Test cases 4-5 satisfy $N\le 2000.$
* Test cases 6-14 satisfy no additional constraints.
输出格式
The first line of input contains a single integer $N.$
The next line contains $N$ space-separated integers $A_1,A_2,\ldots,A_N.$
The next line contains $N$ space-separated integers $Q_1,Q_2,\ldots,Q_N.$
Print $N$ lines, the $i$-th of which contains the journey length for cow $i.$
The next line contains $N$ space-separated integers $A_1,A_2,\ldots,A_N.$
The next line contains $N$ space-separated integers $Q_1,Q_2,\ldots,Q_N.$
Print $N$ lines, the $i$-th of which contains the journey length for cow $i.$
输入输出样例
输入 #1
4 3 5 10 2 3 3 2 1
输出 #1
7/2 7/2 5/1 -1
Consider the answer for the cow originally on world 2. At time $2$ worlds 1
and 2 align, so the cow can travel to world 1. At time $\frac{7}{2}$ worlds 1
and 3 align, so the cow can travel to world 3.
and 2 align, so the cow can travel to world 1. At time $\frac{7}{2}$ worlds 1
and 3 align, so the cow can travel to world 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted