Codeforces 283A

思路:lazy标记,每次只记录最后那个数的增量,需要是再向前传递。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long int Delta[200005], a[200005];
double sum;
int main(int argc, char const *argv[]) 
{
    int n, type, add, pos, j;
    while(~scanf("%d", &n))
    {
        sum = 0.;
        memset(Delta, 0, sizeof(Delta));
        a[1] = 0;
        j = 1;
        for(int i = 0; i < n;i ++)
        {
            scanf("%d", &type);
            if(type == 1)
            {
                scanf("%d%d", &pos, &add);
                Delta[pos] += add;
                sum += add*pos;
            }
            else if(type == 2)
            {
                scanf("%d", &add);
                a[++j] = add;
                sum += add;
            }
            else
            {
                sum -= a[j] + Delta[j];
                Delta[j-1] += Delta[j];
                Delta[j--] = 0;
            }
            printf("%.7lf\n", sum/j);
        }
    }
    return 0;
}


posted on 2014-04-30 18:37  wangzhili  阅读(87)  评论(0编辑  收藏  举报