A8916 | Cows and Sequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform $n$ operations. Each operation is one of the following:
1. Add the integer $x_{i}$ to the first $a_{i}$ elements of the sequence.
2. Append an integer $k_{i}$ to the end of the sequence. (And hence the size of the sequence increases by 1)
3. Remove the last element of the sequence. So, the size of the sequence decreases by one. Note, that this operation can only be done if there are at least two elements in the sequence.
After each operation, the cows would like to know the average of all the numbers in the sequence. Help them!
1. Add the integer $x_{i}$ to the first $a_{i}$ elements of the sequence.
2. Append an integer $k_{i}$ to the end of the sequence. (And hence the size of the sequence increases by 1)
3. Remove the last element of the sequence. So, the size of the sequence decreases by one. Note, that this operation can only be done if there are at least two elements in the sequence.
After each operation, the cows would like to know the average of all the numbers in the sequence. Help them!
输入格式
The first line contains a single integer $n (1<=n<=2·10^{5})$ — the number of operations. The next $n$ lines describe the operations. Each line will start with an integer $t_{i}$ $(1<=t_{i}<=3)$ , denoting the type of the operation (see above). If $t_{i}=1$ , it will be followed by two integers $a_{i},x_{i}$ $(|x_{i}|<=10^{3}; 1<=a_{i})$ . If $t_{i}=2$ , it will be followed by a single integer $k_{i}$ $(|k_{i}|<=10^{3})$ . If $t_{i}=3$ , it will not be followed by anything.
It is guaranteed that all operations are correct (don't touch nonexistent elements) and that there will always be at least one element in the sequence.
It is guaranteed that all operations are correct (don't touch nonexistent elements) and that there will always be at least one element in the sequence.
输出格式
Output $n$ lines each containing the average of the numbers in the sequence after the corresponding operation.
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$ .
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$ .
输入输出样例
输入 #1
5 2 1 3 2 3 2 1 3
输出 #1
0.500000 0.000000 1.500000 1.333333 1.500000
输入 #2
6 2 1 1 2 20 2 2 1 2 -3 3 3
输出 #2
0.500000 20.500000 14.333333 12.333333 17.500000 17.000000
In the second sample, the sequence becomes 
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted