先上题目:

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. openstack liberty aio nova 调试

  2. openStack Packages yum upgrade

    依赖关系解决 ============================================================================================= ...

  3. vue项目打包之后首页白屏的问题

    本地的vue项目在server端浏览没问题,但是执行npm run build 打包之后在本地预览是白屏. 解决方法 1.路径问题 在config文件夹中找到index.js打开把assetsPubl ...

  4. 【转载】UML图示与代码对照

    一.类继承 public class Father { } public class Child : Father { } 二.接口继承 public interface IBreath { } pu ...

  5. MySQL索引失效及使用索引的优缺点

    本文所有实验基于MySQL5.7.21,实验将会用到Explain工具,不了解的同学可参考此文章:MySQL性能优化神器Explain详解 联合索引失效 先创建一个包含三个字段的联合索引,索引顺序如下 ...

  6. day03_12/13/2016_bean的管理之依赖注入

  7. 表格对象的获取和更改(原生js)

    表格对象的获取 var oT = document.getElementById("tb"); //获取head console.log(oT.tHead); console.lo ...

  8. ZUK 22(Z2131) 免解锁BL 免rec 保留数据 Magisk Xposed 救砖 ROOT ZUI 4.0.199

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  9. HDU_1087_Super Jumping! Jumping! Jumping!_dp

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  10. day10-函数基础知识

    函数 什么是函数 把工具事先准备好,然后下次使用的时候,直接使用就行了.我们的函数就是工具 为何用函数 1.遇到重复的功能只能重复编写实现代码,代码冗余 2.功能需要扩展时,需要找出所有实现该功能的地 ...