先上题目:

C. Cows and Sequence
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  1. Add the integer xi to the first ai elements of the sequence.
  2. Append an integer ki 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!

Input

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

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.

Sample test(s)
input
5
2 1
3
2 3
2 1
3
output
0.500000
0.000000
1.500000
1.333333
1.500000
input
6
2 1
1 2 20
2 2
1 2 -3
3
3
output
0.500000
20.500000
14.333333
12.333333
17.500000
17.000000
Note

In the second sample, the sequence becomes 

  题意:给你三种操作,给前ai个数都加上一个数;在序列末尾加一个数,去除序列末尾的数,每种操作以后输出当前序列的平均值,一开始序列有一个0,保证操作合法,序列里至少有一个数。

  比赛的时候想的太复杂了。想了一种更广泛的操作,可以在任意区间加数的。然后就想到了盛爷讲的树状数组的区间修改,单点查询什么的,然后一直调代码,结果白白浪费了2个小时,结果还是错了。这里有的特出条件就是加数的区间的其中一端是固定在开头,所以其实只需要用一个变量保存总值,然后对于区间添加的时候就直接标记一下是到哪里的区间,在删除的时候就将标记前移就可以了。

  又打了一场脑子进水的比赛······

上代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define MAX 300200
#define ll long long
#define lowbit(x) (x&(-x))
using namespace std; ll d[MAX];
ll ma[MAX]; int n; int main()
{
int ti,m,a,x;
ll p,ss;
double avg;
//freopen("data.txt","r",stdin);
while(scanf("%d",&m)!=EOF){
// memset(d,0,sizeof(ll)*(lim+1));
// memset(ma,0,sizeof(ll)*(lim+1));
n=;
ss=;
d[]=;
for(int i=;i<m;i++){
scanf("%d",&ti);
switch(ti){
case :
scanf("%d %d",&a,&x);
ma[a]+=x;
ss+=a*x;
break;
case :
scanf("%d",&x);
ss+=x;
n++;
d[n]=x; ma[n]=;
break;
case :
ss-=d[n]+ma[n];
ma[n-]+=ma[n];
n--;
break;
}
avg=ss*1.0/n;
printf("%.6lf\n",avg);
}
//putchar('\n');
}
return ;
}

/*Cows and Sequence*/

CodeForces - 284C - Cows and Sequence的更多相关文章

  1. codeforces C. Cows and Sequence 解题报告

    题目链接:http://codeforces.com/problemset/problem/284/C 题目意思:给出3种操作:t = 1:在前 a 个数中每个数都加上x: t= 2:在数组末尾增加一 ...

  2. Codeforces 486E LIS of Sequence(线段树+LIS)

    题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...

  3. codeforces 284 C. Cows and Sequence(线段树)

    题目链接:http://codeforces.com/contest/284/problem/C 题意:就是给出3个操作 1)是将前i 个数加x 2)在数组最后添加一个数x 3)删除数组最后的那个数 ...

  4. CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)

    E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...

  5. Codeforces GYM 100114 C. Sequence 打表

    C. Sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description ...

  6. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. codeforces 675A A. Infinite Sequence(水题)

    题目链接: A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. Codeforces 487C. Prefix Product Sequence 逆+结构体

    意甲冠军: 对于数字n, 他询问是否有1~n置换 这种布置能够在产品上模每个前缀n 有可能0~n-1 解析: 通过观察1肯定要在首位,n一定要在最后 除4意外的合数都没有解 其它质数构造 a[i]=i ...

  9. Codeforces 670E - Correct Bracket Sequence Editor - [线段树]

    题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...

随机推荐

  1. PCB NOSQL MongoDb MI流程指示数据存储结构

    一.MI流程指示结构 二.产品型号树结构(即盲埋孔板型号结构) 三.MI流程指示UI 小结:1.MI流程指示使用的表非常之多(30多张表),存储的数据分散到各个表中,而NOSQL 一个产品型号一条记录 ...

  2. Akka源码分析-Remote-位置透明

    上一篇博客中,我们研究了remote模式下如何发消息给远程actor,其实无论如何,最终都是通过RemoteActorRef来发送消息的.另外官网也明确说明了,ActorRef是可以忽略网络位置的,这 ...

  3. jQuery里$.post请求,后台返回结果为“json”格式,前台解析错误问题记录

    在JSP页面使用$.post请求后台返回json数据时,在最后 必须加上返回数据格式为json的才行.不然JSP页面解析会出错.

  4. action="post" 、 servletconfig 、 servletcontext 、getPrintWiter() 、context-param、 init-param(第一个完整的servlet)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  5. Jquery 实现列表的显示和隐藏

    本人github源码下载地址:https://github.com/liuyanpeng521/ListChange.git

  6. dropdownlist显示树形结构

    /// <summary> /// 递归 /// </summary> /// <param name="deplist"></param ...

  7. Puppeteer——自动化脚本设计

    我被分配了一个繁琐的任务,就是要给100个相同的站点做同样的配置.曾经就有做过相同的事,那时还不会写脚本,全靠手动配置.机械的配置了两天的时间,身体感觉被掏空.所以这次我决定还是写一个脚本自动的进行配 ...

  8. 程序员的幽默-献给所有Java程序员

    1. 一程序员去面试,面试官问:“你毕业才两年,这三年工作经验是怎么来的?!”程序员答:“加班.” 2. 某程序员对书法十分感兴趣,退休后决定在这方面有所建树.于是花重金购买了上等的文房四宝.一日,饭 ...

  9. [Windows Server 2008] 安装PHP+MySQL方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:PHP+MyS ...

  10. Linux 查询PID和端口号

    https://www.cnblogs.com/understander/p/5546458.html