Codeforces Round #174 (Div. 2)---C. Cows and Sequence(操作序列)

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!

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 integers ai,?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

用st数组来保存这些数,size表示有多少个数,add数组表示st数组每一个数字应该增加的值

然后实时记录和

/*************************************************************************
    > File Name: CF-174-C.cpp
    > Author: ALex
    > Mail: [email protected]
    > Created Time: 2015年04月09日 星期四 22时07分59秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

static const int N = 200100;
int st[N];
int add[N];

int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        int o, a, x;
        double sum = 0;
        int size = 1;
        st[1] = 0;
        memset(add, 0, sizeof(add));
        while (n--)
        {
            scanf("%d", &o);
            if (o == 3 && size >= 2)
            {
                sum -= (st[size] + add[size]);
                add[size - 1] += add[size];
                add[size] = 0;
                --size;
            }
            else if (o == 1)
            {
                scanf("%d%d", &a, &x);
                sum += (double)a * x;
                add[a] += x;
            }
            else
            {
                scanf("%d", &x);
                ++size;
                st[size] = x;
                sum += x;
            }
            printf("%.10f\n", sum / size);
        }
    }
    return 0;
}
时间: 2024-09-30 19:22:07

Codeforces Round #174 (Div. 2)---C. Cows and Sequence(操作序列)的相关文章

Codeforces Round #174 (Div. 2)---D. Cow Program(dp, 记忆化搜索)

Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1,?a2,?-,?an of positive integers: Initially, x?=?1 and y?=?0. If, after any step, x

Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor

E. Correct Bracket Sequence Editor Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical express

Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 线段树模拟

E. Correct Bracket Sequence Editor Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical express

Codeforces Round #182 (Div. 2)---C. Yaroslav and Sequence(不错的题,分析找规律)

Yaroslav has an array, consisting of (2·n?-?1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them b

Codeforces Round #220 (Div. 2)D. Inna and Sequence 树状数组+二分

题目链接:D. Inna and Sequence 题意:三种操作,1往序列后面加个1,0往序列后面加个0,-1,把给定位置上的数删除. 题解:用树状数组保存的数没被删的个数,每次二分找到位置,然后用数组标记这里被删除. #include<bits/stdc++.h> #include<set> #include<iostream> #include<string> #include<cstring> #include<algorithm&

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿