codeforces -- 283A
3 seconds
256 megabytes
standard input
standard output
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:
- Add the integer xi to the first ai elements of the sequence.
- Append an integer ki to the end of the sequence. (And hence the size of the sequence increases by 1)
- 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·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer ti (1 ≤ ti ≤ 3), denoting the type of the operation (see above). If ti = 1, it will be followed by two integersai, xi (|xi| ≤ 103; 1 ≤ ai). If ti = 2, it will be followed by a single integer ki (|ki| ≤ 103). If ti = 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.
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.
5
2 1
3
2 3
2 1
3
0.500000
0.000000
1.500000
1.333333
1.500000
6
2 1
1 2 20
2 2
1 2 -3
3
3
0.500000
20.500000
14.333333
12.333333
17.500000
17.000000 思路:lazy标记,每次只记录最后那个数的增量,需要是再向前传递。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long int Delta[], a[];
double sum;
int main(int argc, char const *argv[])
{
int n, type, add, pos, j;
while(~scanf("%d", &n))
{
sum = .;
memset(Delta, , sizeof(Delta));
a[] = ;
j = ;
for(int i = ; i < n;i ++)
{
scanf("%d", &type);
if(type == )
{
scanf("%d%d", &pos, &add);
Delta[pos] += add;
sum += add*pos;
}
else if(type == )
{
scanf("%d", &add);
a[++j] = add;
sum += add;
}
else
{
sum -= a[j] + Delta[j];
Delta[j-] += Delta[j];
Delta[j--] = ;
}
printf("%.7lf\n", sum/j);
}
}
return ;
}
codeforces -- 283A的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 一个library,相当于一个rootfolder
picLib.RootFolder.SubFolders 操作library的方式: SPList oList = web.Lists[ListName ...
- declare-styleable:自定义控件的属性
http://www.cnblogs.com/jisheng/archive/2013/01/10/2854891.html 在使用过程中, 1 TypedArray a = getContext() ...
- Java 读取Properties 配置文件
方法一,使用 io 包中的 BufferedInputStream 以及 FileInputStream读入文件转成字符流,然后使用 lang 包中 的 Properties 的 load 方法进行读 ...
- Visual 2012 常用快捷键
快捷键 功能说明 Crtl+K,Crtl+C 注释光标所在行,或选中行 Crtl+K,Crtl+U 反注释光标所在行,或选中行 Crtl+K,Crtl+F 格式化全文 F12 转到定义 Shift + ...
- React初探
经过几天根据官方文档和博园中一些大牛的文章,在了解过基础的语法和组件后,总结一下: 1.第一件事就是分析界面,理想状态下是让每个组件只做一件事情,也就是单一职责,相互嵌套.我认为: 构建组件树,整体的 ...
- 请描述一下 cookies,sessionStorage 和 localStorage 的区别?
http://handyxuefeng.blog.163.com/blog/static/454521722013111714040259/ http://book.51cto.com/art/201 ...
- gulp分享文档
Grunt--I/O操作: 读取A → A.a() → 写出A → 读取A → A.b() → 写出A; gulp--数据流:读取A → A.a() → A.b() → 写出A. Part① 构建gu ...
- CSS图片去色
.imgFilter { filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); ...
- Visual studio 2015程序转Eclipse gun编译出现的问题总结
Visual studio 2015程序转Eclipse gun编译出现的问题总结 1.C++11支持 1)Project settings project右键-> c/c++ build -& ...
- LINUX命令行操作
Linux 命令行快捷键 7条回复 涉及在linux命令行下进行快速移动光标.命令编辑.编辑后执行历史命令.Bang(!)命令.控制命令等.让basher更有效率. 说明 Ctrl – k: 先按住 ...