先上题目:

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. 单纯形&&线性规划

    沦为了背板子...wyfcyx的ppt #include<bits/stdc++.h> using namespace std; ; , inf = 1e18; int n, m, l, ...

  2. 如何通过DirectInput技术针对莱仕达雷驰V3II游戏方向盘编程

    三自由度的动感座椅可以让玩游戏人员在玩的过程中随座椅一起晃动,通过应用程序对方向盘动作的抓取来实现体感,动作类型主要分为加速(后仰,对应踩油门).减速(前倾,对应踩刹车 ).左转(向左打方向盘).右转 ...

  3. Rails mysql数据库连接的小坑

    基本上直接clone下来的话,数据库连接必失败.   注意,把用户名密码写在.env文件下

  4. oracle数据库简单操作

    导入某用户所有表和数据:imp sgp/sgp@192.168.0.99:1521/orcl file=sgp20161025.dmp full=y 导出指定表及数据:exp sgp/sgp@192. ...

  5. [Swift通天遁地]七、数据与安全-(17)使用Swift实现原生的3DES加密和解密

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. 为什么使用HttpServlet?http协议特点、servlet

    因为只有HttpServlet是基于http协议,实现Servlet接口,而http协议是短连接协议,能够实现客户端访问服务端后,数据交互后 连接自动断开.同时http协议基于tcp.ip协议,封装了 ...

  7. scala 变量定义,基本操作符

    scala是jvm语言,它将面向对象与函数风格结合的很好,它可以访问任何java类库并很好的结合使用. 它可以使程序更简单,同时可利用并发的威力. scala基本语法: package com.tes ...

  8. Hadoop基础(一)

    Hadoop 基础知识 大数据已经火了很长很长时间了,从最开始是个公司都说自己公司的数据量很大,我们在搞大数据.到现在大数据真的已经非常成熟并且已经在逐渐的影响我们的生产生活.你可能听过支付宝的金融大 ...

  9. Html常用标签及全称

    <!-- 块标签 divsion --><div></div> <!--br 换行    break--> <br /> <!--分割 ...

  10. Leetcode0523--Continuous Subarray Sum 连续和倍数

    [转载请注明]https://www.cnblogs.com/igoslly/p/9341666.html class Solution { public: bool checkSubarraySum ...