A8590 | Cutting a Fence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya the carpenter has an estate that is separated from the wood by a fence. The fence consists of $n$ planks put in a line. The fence is not closed in a circle. The planks are numbered from left to right from 1 to $n$ , the $i$ -th plank is of height $a_{i}$ . All planks have the same width, the lower edge of each plank is located at the ground level.
Recently a local newspaper "Malevich and Life" wrote that the most fashionable way to decorate a fence in the summer is to draw a fuchsia-colored rectangle on it, the lower side of the rectangle must be located at the lower edge of the fence.
Vasya is delighted with this idea! He immediately bought some fuchsia-colored paint and began to decide what kind of the rectangle he should paint. Vasya is sure that the rectangle should cover $k$ consecutive planks. In other words, he will paint planks number $x$ , $x+1$ , $...$ , $x+k-1$ for some $x$ $(1<=x<=n-k+1)$ . He wants to paint the rectangle of maximal area, so the rectangle height equals $min\ a_{i}$ for $x<=i<=x+k-1$ , $x$ is the number of the first colored plank.
Vasya has already made up his mind that the rectangle width can be equal to one of numbers of the sequence $k_{1},k_{2},...,k_{m}$ . For each $k_{i}$ he wants to know the expected height of the painted rectangle, provided that he selects $x$ for such fence uniformly among all $n-k_{i}+1$ possible values. Help him to find the expected heights.
Recently a local newspaper "Malevich and Life" wrote that the most fashionable way to decorate a fence in the summer is to draw a fuchsia-colored rectangle on it, the lower side of the rectangle must be located at the lower edge of the fence.
Vasya is delighted with this idea! He immediately bought some fuchsia-colored paint and began to decide what kind of the rectangle he should paint. Vasya is sure that the rectangle should cover $k$ consecutive planks. In other words, he will paint planks number $x$ , $x+1$ , $...$ , $x+k-1$ for some $x$ $(1<=x<=n-k+1)$ . He wants to paint the rectangle of maximal area, so the rectangle height equals $min\ a_{i}$ for $x<=i<=x+k-1$ , $x$ is the number of the first colored plank.
Vasya has already made up his mind that the rectangle width can be equal to one of numbers of the sequence $k_{1},k_{2},...,k_{m}$ . For each $k_{i}$ he wants to know the expected height of the painted rectangle, provided that he selects $x$ for such fence uniformly among all $n-k_{i}+1$ possible values. Help him to find the expected heights.
输入格式
The first line contains a single integer $n$ $(1<=n<=10^{6})$ — the number of planks in the fence. The second line contains a sequence of integers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{9}$ ) where $a_{i}$ is the height of the $i$ -th plank of the fence.
The third line contains an integer $m$ $(1<=m<=10^{6})$ and the next line contains $m$ space-separated integers $k_{1},k_{2},...,k_{m}$ $(1<=k_{i}<=n)$ where $k_{i}$ is the width of the desired fuchsia-colored rectangle in planks.
The third line contains an integer $m$ $(1<=m<=10^{6})$ and the next line contains $m$ space-separated integers $k_{1},k_{2},...,k_{m}$ $(1<=k_{i}<=n)$ where $k_{i}$ is the width of the desired fuchsia-colored rectangle in planks.
输出格式
Print $m$ whitespace-separated real numbers, the $i$ -th number equals the expected value of the rectangle height, if its width in planks equals $k_{i}$ . The value will be considered correct if its absolute or relative error doesn't exceed $10^{-9}$ .
输入输出样例
输入 #1
3 3 2 1 3 1 2 3
输出 #1
2.000000000000000 1.500000000000000 1.000000000000000
输入 #2
2 1 1 3 1 2 1
输出 #2
1.000000000000000 1.000000000000000 1.000000000000000
Let's consider the first sample test.
- There are three possible positions of the fence for $k_{1}=1$ . For the first position $(x=1)$ the height is 3, for the second one $(x=2)$ the height is 2, for the third one $(x=3)$ the height is 1. As the fence position is chosen uniformly, the expected height of the fence equals ;
- There are two possible positions of the fence for $k_{2}=2$ . For the first position $(x=1)$ the height is 2, for the second one $(x=2)$ the height is 1. The expected height of the fence equals ;
- There is the only possible position of the fence for $k_{3}=3$ . The expected height of the fence equals 1.
- There are three possible positions of the fence for $k_{1}=1$ . For the first position $(x=1)$ the height is 3, for the second one $(x=2)$ the height is 2, for the third one $(x=3)$ the height is 1. As the fence position is chosen uniformly, the expected height of the fence equals ;
- There are two possible positions of the fence for $k_{2}=2$ . For the first position $(x=1)$ the height is 2, for the second one $(x=2)$ the height is 1. The expected height of the fence equals ;
- There is the only possible position of the fence for $k_{3}=3$ . The expected height of the fence equals 1.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted