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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- HTML5 新功能
HTML5 中的一些有趣的新特性: 用于绘画的 canvas 元素 用于媒介回放的 video 和 audio 元素 对本地离线存储的更好的支持 新的特殊内容元素,比如 article.footer. ...
- java开发规范总结_代码编码规范
规范需要平时编码过程中注意,是一个慢慢养成的好习惯 1.基本原则 强制性原则: 1.字符串的拼加操作,必须使用StringBuilder: 2.try…catch的用法 try{ }c ...
- 使用methodSignatureForSelector与forwardInvocation实现消息转发 (转)
转自:http://blog.sina.com.cn/s/blog_8c87ba3b0102v006.html 在给程序添加消息转发功能以前,必须覆盖两个方法,即methodSignatureForS ...
- Object layout in C++ and access control
The variables are guaranteed to be laid out contiguously, as in C. However, the access blocks may no ...
- Google HTML/CSS/JS代码风格指南
JS版本参见:http://www.zhangxinxu.com/wordpress/2012/07/google-html-css-javascript-style-guides/ HTML/CSS ...
- Linux 信号量互斥编程
所谓信号量,其实就是一个数字.内核给这个数字赋予一定的含义,让它等于不同的值时所表示的意义不同.这样就可以用它来标示某种资源是否正被使用.信号的分类其实挺多的,主要还是二值和计数器.这里讨论二值 现在 ...
- yii1.1.15 accessRules的一个小bug
public function accessRules() { return array( array( 'allow', 'actions'=>array('ajaxChangeImage', ...
- php 扩展编译linux
进入扩展库目录:$cd phpredis-master 需要root权限执行 执行:$ phpize 执行:$ ./configure 执行:$ make 执行:$ make install 编译 ...
- jQuery 侧栏菜单点击body消失
其实就在弹出菜单时 让菜单外部有个全屏大小的遮罩层
- Activity singleInstance启动模式
全局单例模式 如果 是新建Activity, 则新建一个Task, 然后将ActivityRecord单独放在其中 如果已经存在这个Activity, 则直接将这个Activity转到前台